使用charset utf-8时出错

时间:2014-04-27 15:52:36

标签: php mysql oop pdo

当我使用函数mysql_set_charset('utf8');时出现此错误:

  

警告:mysql_set_charset()要求参数2为资源,对象在第4行的D:\ wamp \ www \ plateforme \ includes \ db.php中给出 < / p>

这是代码:

<?php

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

?>

1 个答案:

答案 0 :(得分:6)

您正在混合mysql_*PDO,将这样的字符编码设置为现有的连接对象并删除mysql_set_charset('utf8',$db); ..

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