简体   繁体   中英

Error when using charset utf-8

When I use the function mysql_set_charset('utf8'); I have this error :

Warning: mysql_set_charset() expects parameter 2 to be resource, object given in D:\\wamp\\www\\plateforme\\includes\\db.php on line 4

This is the code :

<?php

$db = new PDO('mysql:host=localhost;dbname=plateforme', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 
mysql_set_charset('utf8',$db);

?>

You are mixing mysql_* and PDO , Set the character encoding like this to your existing connection object and remove that mysql_set_charset('utf8',$db); ..

$db = new PDO('mysql:host=localhost;dbname=plateforme;charset=utf8', 'root', '');
                                                      ^^^^^^^^^^^^^ //<--- This.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM