使用字符集utf-8时出错


Error when using charset utf-8

当我使用函数mysql_set_charset('utf8');时,我会出现以下错误:

警告:mysql_set_charset()要求参数2是第4行D:''wamp''www''platforme''includes''db.php中给定的资源对象

这是代码:

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

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

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