Mysql选择给php中的错误答案 [英] Mysql select giving the wrong answer inside php
问题描述
我在使用PHP脚本查询mysql数据库时遇到这个问题。
I have this issue with a PHP script when querying a mysql DB.
查询是:
SELECT COUNT(*) FROM theTable WHERE fieldValue = ‘Dom-Rémy'
$ b b
我已经检查,当在管理控制台(phpMyAdmin)手工执行此查询时,我可以找到一个匹配请求的记录,这是我期望的。
I have checked that when performing by hand this query in the administration console (phpMyAdmin) I can find one record matching the request, which is what I expect.
但是在PHP脚本中,代码如下,我总是获得0条记录(而不是1):
But inside a PHP script where the code is as follows, I always get 0 records (instead of 1):
$Query = "SELECT COUNT(*) FROM theTable WHERE fieldValue = 'Dom-Rémy'";
$DBR = mysql_query($Query,$Connection);
$NBR = mysql_result($DBR,0,0);
printf("NBR: %d\n",$NBR);
为什么?我怀疑fieldValue中的欧洲字符是什么原因导致的问题,但我该怎么做,使其工作?
Why is that? I suspect the european character inside the fieldValue is what causes the problem, but what should I do to make it work?
推荐答案
类似这样之前的查询设置客户端的字符集和结果:
Using something like this before Your query to set charset of client and results:
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
这篇关于Mysql选择给php中的错误答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!