I’m building a website that allows members to upload images.
The images themselves are not stored in the database - just the image information
(id, title, filename, thumbnail, date, ownerid).
I created small test tables in PHPMyAdmin, and everything was working fine until I got my image upload script working.
Apparently, SQL doesn’t recognize strings that are inserted by my script.
In other words:
SELECT * FROM 'image'
Returns all records
SELECT * FROM 'image' WHERE 'title' LIKE "Some Title"
Returns the row with "Some Title" if it was inserted by PHPMyAdmin.
SELECT * FROM 'image' WHERE 'title' LIKE "Some Title"
Returns 0 records if "Some Title" was inserted through my PHP script.
If I copy and paste or type the words "Some Title" in PHPMYAdmin:
SELECT * FROM 'image' WHERE 'title' LIKE "Some Title"
Now returns the correct data.
It *seems like I didn’t change anything, and it still looks like the same string to me, but to SQL
“Some Title” != “Some Title” for some mysterious reason.
Incidentally, all of the other rows with strings have the same issue.
Here’s what I’ve tried:
SHOW CREATE TABLE:
CREATE TABLE `image`
(`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`filename` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`thumbnail` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`date` date NOT NULL, `ownerid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`))
ENGINE=MyISAM AUTO_INCREMENT=43 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
SHOW CREATE DATABASE:
CREATE DATABASE `imagedb` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */
Of course, when I connect to my database, I always run:
!mysqli_set_charset($link, 'utf8')
All of my html and php pages contain:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Someone suggested putting this at the top of my script:
ini_set('default_charset', 'UTF-8');
It didn't help, so I removed it.
I’ve already tried going through each table with PHPMyAdmin and
setting the collation for each column manually.
I also tried running this script:
SET character_set_results = 'utf8', character_set_client = 'utf8',
character_set_connection = 'utf8', character_set_database = 'utf8',
character_set_server = 'utf8'
Maybe it’s not an encoding (collation) problem after all…
But I’m stumped, so any help would be appreciated!