PHP MySQL utf 8 encoding

2019-04-11 16:37发布

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.

My query looks like this

$query = "SELECT * FROM mytable WHERE field LIKE '%$string%'"

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

标签: php mysql utf-8
2条回答
戒情不戒烟
2楼-- · 2019-04-11 16:46

in my case, I had to add this line:

mysqli_set_charset($con,"utf8mb4");
查看更多
唯我独甜
3楼-- · 2019-04-11 17:07

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);

?>
查看更多
登录 后发表回答