I am using PHP 5.5, and when I try to insert a UTF-8 character into a MySQL database, PDO disables it with the first character other than ASCII.
I established my connection:
(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASS, array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING))
I tried SET NAMES that all messages, but this does not work either because the problem is NOT on the MySQL side.
When I insert through phpMyAdmin and directly from the MySQL console, it works! When I select an accented line with PDO, it works!
The only problem is INSERTand UPDATEusing PDO specifically!
Here are the SQL tables. This is all in UTF-8, but maybe someone knows about the conflict between setup and PDO
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_lang` int(11) NOT NULL DEFAULT '2',
`id_tgroup_cat` int(11) NOT NULL,
`fieldfor` int(11) NOT NULL,
`colors` varchar(100) NOT NULL,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=34 ;
I already tried to make the text field varchar and did not change anything.
Valid insert in PHP:
$query = $this->db->prepare("UPDATE mytable
SET text = ?,
colors = ?
WHERE id = ?");
$query->execute(array($text, $colors, $id));
$text = "référence" ( R , ), $colors - , $id - 2.