Mysql selects wrong answer inside php

I have this problem with a PHP script while querying mysql DB.

Request:

SELECT COUNT(*) FROM theTable WHERE fieldValue = 'Dom-Rémy' 

I checked that when I manually execute this request in the administration console (phpMyAdmin), I can find one entry that matches the request, and this is what I expect.

But inside a PHP script, where the code looks like this, I always get 0 entries (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); 

Why? I suspect that the European character inside the fieldValue is causing the problem, but what should I do to make it work?

0
source share
2 answers

Using something like this before setting your request, set the client encoding 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); 
+1
source

Use only counter (*) does not work for a while

 $query = "SELECT COUNT FROM theTable WHERE fieldValue = 'Dom-Rémy'"; $result = mysql_query($query); 
-1
source

All Articles