MySQLi: Non-English Characters

大城市里の小女人 提交于 2019-12-24 12:09:22

问题


I have a Table named "status" Which is used to store objects status. The table has 5 columns and except "symbol" column which it's type is VARCHAR utf8mb4_unicode_ci, All the others are just typical integers.

The problem is that because the symbol column can store English and Non-English characters, It returns NULL(With var_dump($row)) When I use my php file "getStatus.php" to retrieve the data from a row with Non-English symbol but It works well when I use English characters as symbol.

This is my table(the symbol on the second row is "تست"):

This is the php code, "getStatus.php" :

if(!isset($_GET["symbol"]))
        die("please specify the symbol");
$con = mysqli_connect("localhost","root","******","****");
// Check connection
if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT * FROM `status` WHERE `symbol` =  '" . $_GET["symbol"] . "';";
$result = mysqli_query($con,$query);
if (!$result)
        die("unable to retreive status");
$row = mysqli_fetch_assoc($result);
if ($row["status"] == 1)
        echo $row["percentage"];
else
        echo -1;

I can successfully get data When I execute getStatus.php?symbol=EU which calls mysql with

SELECT * FROM `status` WHERE `symbol` = 'ER';

But When I execute getStatus.php?symbol=تست, I got null! The confusing point is that if I copy the query and enter it in mysql command line It will work but it doesn't work when I send the same query with mysqli in php!!

SELECT * FROM `status` WHERE `symbol` = 'تست';

Why it works in mysql commandline and phpmyadmin but not with mysqli?

来源:https://stackoverflow.com/questions/34513812/mysqli-non-english-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!