0

I have this issue with a PHP script when querying a mysql DB.

The query is:

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

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.

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

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?

e4c5
  • 52,766
  • 11
  • 101
  • 134
Michel
  • 10,303
  • 17
  • 82
  • 179

2 Answers2

1

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);
Whencesoever
  • 2,218
  • 15
  • 26
-1

Use only count count(*) wont work some time

$query = "SELECT COUNT FROM theTable WHERE fieldValue = 'Dom-Rémy'";
 $result = mysql_query($query);
rupesh
  • 277
  • 3
  • 15