I am trying to use php to execute mysql query that contains Chinese characters. The following code works on my previous machine.
$sql="
SELECT
部门,
编码
...
FROM pb ";
if ($conn->query($sql)){
echo "sueccess";
}
else{
echo "MySQL Query fail". $conn->error;}
However after migrated to a new machine, where I re-built the database, the code stopped working. I get the "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '�门, 大类 FROM pb' at line 20"
error.
When I change the query to all English characters, I have no error. My guess is something wrong with the Chinese characters I am using.
The new database is a copy of the previous one, only when I was copying it, I have to create a new MySQL database and use the import query to put the data in. I selected " utf8_general_ci" for the old machine and the new machine.
NOTED: the query works in database directly, when I submit the query through phpMyAdmin. But it does not work in the php file.