简体   繁体   English

加快口音MySQL-PHP-UTF-8

[英]Accute accent MySQL - PHP - UTF-8

  • I have set the meta charset to UTF-8 我已将元字符集设置为UTF-8

     <meta charset="utf-8" /> 
  • I have set my Notepad++ encoding to UTF-8 without bom 我已经将我的Notepad ++编码设置为UTF-8,而没有bom

  • I have set my MySql's database collation to ut8_general_ci 我已经将MySql的数据库排序规则设置为ut8_general_ci

  • I have set the collation for each field to utf8_general_ci 我已将每个字段的排序规则设置为utf8_general_ci

I have done all that and I still can't see accute accents (é). 我已完成所有这些操作,但仍然看不到准确的口音(é)。 Instead I see ... Hopefuly you can help me. 相反,我看到了......希望您能帮助我。 Thank you! 谢谢!

be sure to run SET NAMES utf8 on the database 确保在数据库上运行SET NAMES utf8

Example (with the use of PDO): 示例(使用PDO):

$pdo = new PDO('mysql:host=127.0.0.1;dbname=mydb', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

Set also the charset of the database connection. 还要设置数据库连接的字符集。 Setting this parameter will tell your database object to deliver UTF-8 encoded strings, even if they are stored otherwise in the database. 设置此参数将告诉您的数据库对象传递UTF-8编码的字符串,即使它们以其他方式存储在数据库中也是如此。 Of course storing the data in the same format UTF-8 will make the delivering faster. 当然,以相同的UTF-8格式存储数据将使传递速度更快。

// tells the mysqli connection to deliver UTF-8 encoded strings.
$db = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
$db->set_charset('utf8');

// tells the pdo connection to deliver UTF-8 encoded strings.
$dsn = "mysql:host=$dbHost;dbname=$dbName;charset=utf8";
$db = new PDO($dsn, $dbUser, $dbPassword);

// tells the mysql connection to deliver UTF-8 encoded strings.
$db = mysql_connect($dbHost, $dbUser, $dbPassword);
mysql_set_charset('utf8', $db);

more… 更多…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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