0

i have SQL query :

SELECT count(art),art,art_manufacturer,group_manufacturer 
FROM goods 
WHERE art_manufacturer = 'ГКБ-44/150'

when i using phpMyAdmin, result of query is:

1, 950000258, ГКБ-44/150, Интерскол

my php file contain:

$art="ГКБ-44/150";\\debug
$query = "SELECT art,art_manufacturer,group_manufacturer FROM goods WHERE art_manufacturer = '".$art."'"; 
$sql = mysql_query($query); 
while ($recResult = mysql_fetch_array($sql)) 
{ \*do somting*\ }

where is my mistake? why the result of query in php is empty?

my solution i had mysql_query("SET NAMES cp1251"); in my code when i start use mysqli i commented mysql_query("SET NAMES cp1251"); mistakenly i thought mysqli is solution, after i discommented mysql_query("SET NAMES cp1251"); i got problem again.

So what's happend?

my PHP file in UTF-8 and when i use mysql_query("SET NAMES cp1251"); i had SELECT art,art_manufacturer,group_manufacturer FROM goods WHERE art_manufacturer = "ГКБ-44/150"; query to mysql DB

  • Don't use `mysql_*` functions. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Michas Apr 27 '15 at 15:24

2 Answers2

1

It's empty because these are specially reserved characters interpreted by PHP/SQL. I would suggest you take a look at parameterised queries or PDO, they will escape strings for you as part of their function.

EDIT: Also it could be that the encoding of your server doesn't accept Unicode characters. I would ensure your site is using UTF-8.

John Bell
  • 2,350
  • 1
  • 14
  • 23
0

You should stop using mysql_* functions they are deprecated for a long time.

Use mysqli or PDO and bind parameters to the query not concatenate the query string with some not prepared php variables.

So just to help you pass over the issue this time you can:

$query = "SELECT art,art_manufacturer,group_manufacturer 
    FROM goods 
    WHERE art_manufacturer = '".mysql_real_escape_string($art)."'"; 
Alex
  • 16,739
  • 1
  • 28
  • 51