I've been having a problem inserting some data into a varchar field of an InnoDB MySQL table with a PHP script. Initially I thought the problem was caused by using utf8 character encoding because I did some research on the error I was getting, "Incorrect String Value" and found a couple of helpful posts here about switching my tables over to utf8mb4.
So I switched it to 'utf8mb4'. I did this in a couple of different places, in the server settings, the table settings, the database settings, and also in php via mysqli_set_charset. I also tried changing the MySQL setting 'character-set-client-handshake' to see if that would make a difference, but I still got the error even after restarting the MySQL server.
I decided that I would see if my PHP script was the problem so I opened up MySQL Workbench and entered the same query there. Success!
So, now I am really puzzled. Why can I run the query in MySQL workbench but not via PHP? Here is my code.
In MySQL Workbench, this query works:
UPDATE books SET notes = 'Renâe Boivin, jeweller by Cailles, Franðcoise'
WHERE asin LIKE '0704370905'
This is my PHP code for running that same query:
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_set_charset($dbc, 'utf8mb4');
$sql = "UPDATE books SET notes = 'Renâe Boivin, jeweller by Cailles,
Franðcoise' WHERE asin
LIKE '0704370905'";
That code generates this error:
"Error: Incorrect string value: '\xE2e Boi...' for column 'notes' at row 2"
Any ideas? Maybe I'm just overlooking something really simple. I appreciate any suggestions. Thank you!