PHP MySQL UTF 8编码 [英] PHP MySQL utf 8 encoding
本文介绍了PHP MySQL UTF 8编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图对从数据库中提取数据的PHP函数进行Ajax调用.但是我遇到了一个问题.
My trying to make an Ajax call to a PHP function that pulls out data from my database. I've run into a problem though.
我的查询看起来像这样
$query = "SELECT * FROM mytable WHERE field LIKE '%$string%'"
然后我检查查询返回的行数,但是当我键入æøå时,我的查询返回0行,尽管我知道数据库中存在带有æøå的条目.为什么是这个
I then check on the number of rows returned by the query, but when i type in æ ø å then i my query returns 0 rows, although I know there are entries in the database that have æ ø å.. why is this
推荐答案
设置连接以使用UTF-8:
Set the connection to use UTF-8:
<?php
// MySQLi:
$connection = new MySQLi( /* ... credentials ...*/);
$connection->set_charset("utf8");
// MySQL:
$connection = mysql_connect(/* ... credentials ... */);
mysql_set_charset("utf8", $connection);
?>
这篇关于PHP MySQL UTF 8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文