简体   繁体   English

SQL查询的最佳字符集编码是什么?

[英]What is the best charset encoding for sql query?

For example russian characters not reading, accent letters not read. 例如俄语字符不阅读,重音字母不阅读。

I tried with mysqli_set_charset("cp1251") and with utf8 , not working. 我尝试使用mysqli_set_charset("cp1251")utf8 ,但无法正常工作。

I've tryed to insert string in sql like this htmlentities($str, ENT_QUOTES, "UTF-8"); 我试图像这样的htmlentities($str, ENT_QUOTES, "UTF-8");在sql中插入字符串htmlentities($str, ENT_QUOTES, "UTF-8"); and for accent letters working perfectly but for russian characters the result is like this Øóôóòèíñêèé Ìèõàèë . 对于重音字母来说效果很好,但是对于俄语字符来说,结果就像ØóôóòèíññèèéÌèõàèë

Thanks. 谢谢。

It is important to use the same character set in the complete data chain. 在整个数据链中使用相同的字符集非常重要。 Mixed encodings will always cause problems. 混合编码总是会引起问题。

  • Set the table or column encoding to charset x 将表或列的编码设置为字符集x
  • Set the database connection encoding to charset x 将数据库连接编码设置为charset x
  • Set the internal encoding of PHP to charset x or convert the string 将PHP的内部编码设置为charset x或转换字符串
  • Set the input and output client (mysql console, browser or cli) encoding to charset x 将输入和输出客户端(mysql控制台,浏览器或cli)的编码设置为charset x
  • When you are using a browser check the encoding which is set in the http header, too. 使用浏览器时,还要检查在HTTP标头中设置的编码。 Depending on the browser this value might overwrite an exisiting meta tag in the html header! 根据浏览器的不同,此值可能会覆盖html标头中的现有meta标签!

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

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