I have problem with query charset for mysql bd in php script.
I'm placing GET parameter inside select query and it work good for all Latin characters, but with Cyrillic characters it returns me empty table. If I place some value with Cyrillic in query instead of GET parameter, query works as I want. Likewise, I get result query inside php-Admin and it works.
All Cyrillic characters in result shows me correct.
I've checked everything: php-file is utf8, GET parameter value is utf8, mysql_client_encoding() returns me utf8.
I've tried all I found - nothing helps me.
header('Content-type:text/html; charset=utf-8');
mysql_set_charset('utf8', $link);
mysql_query("SET NAMES utf8", $link);
mysql_query("SET CHARACTER SET 'utf8'", $link);
mysql_query("SET SESSION collation_connection = 'utf8_general_ci'", $link);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $link);
All of this DOESN'T HELP.
Here is my php script.
<?php
$link = mysql_connect('localhost', 'r96036lg_searche', 'Jh1ZT4]^');
//mysql_set_charset('utf8', $link);
//mysql_query("SET NAMES utf8", $link);
//mysql_query("SET CHARACTER SET 'utf8'", $link);
//mysql_query("SET SESSION collation_connection = 'utf8_general_ci'", $link);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $link);
//echo mysql_client_encoding($link);
mysql_select_db('r96036lg_searche', $link);
//mysqli::set_charset('utf8');
$query = "select id, name, typeid from MainObjects where used = 1";
if(isset($_GET['name']) && !empty($_GET['name'])) {
//$name = mb_convert_encoding($_GET['name'], "UTF-8", "win1251");
$name = $_GET['name'];
//echo mb_detect_encoding($name, "auto", false);
//$name = iconv(mb_detect_encoding($name, "auto", false), "UTF-8", $name);
//echo $name;
$query .= " and typeid = 1 and (name like '%".$name.
"%' or id in (select parentid from MainObjects where name like '%"
.$name."%' and used = 1))";
}
//echo $query;
$result = mysql_query($query, $link);
if(!$result) echo mysql_error();
else {
$out = "[";
while($row = mysql_fetch_row($result)) {
... //here is myoutput
}
$out .= "]";
echo $out;
}
?>
json_encodeinstead.echo $query);? Did you already try to run this in phpmyadmin ?JSONused only for output - there is no problem with it. And yes, I've tried it in phpadmin - it works. @LorenzMeyer