Jump to content

search mysql to support utf


strangermaster

Recommended Posts

hi

Server mysql 5/php5,2

I have a quaery working perfect in php myadmin :

Select Name from Regions where Name like 'é%' order by Name ASC limit 0,5 for French or this one for russian :

Select Name from Regions where Name like 'й%' order by Name ASC limit 0,5

 

But in my real systeme (ajax field autocomplete) it doesnot - only for normal latin characters ! No reponse att all in php :

 

<?php
    //headers
    header("Content-Type: text/plein; charset=UTF-8");
  	header("Cache-Control: no-cache, private");  
    header("Pragma: no-cache");
    
    
    
    //database information
    $sDBServer = "";
    $sDBName = "";
    $sDBUsername = "";
    $sDBPassword = "";
    

$oData = json_decode($HTTP_RAW_POST_DATA);

$aSuggestions = array();

    //make sure there's text
    if (strlen($oData->text) > 0) {

        //create the SQL query string
$sQuery = "Select Name from ".$oData->requesting." where Name like '".$oData->text."%' order by Name ASC limit 0,".$oData->limit;
              
        //make the database connection
        $oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword);
        @mysql_select_db($sDBName) or die("Unable to open database");
        
        $query  = "SELECT Name from ".$oData->requesting." where Name like '".$oData->text."%' order by Name ASC limit 0,".$oData->limit;
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
array_push($aSuggestions,$row['Name']);
} 
        
    }
    
    


    
   //print_r($aSuggestions);
    
//echo($oJSON->encode($aSuggestions));
  echo(json_encode($aSuggestions));
    echo($sQuery);
?>

 

My data field in table is set to utf8_general_ci as i can see handeles well european, russian, latin caracters.

 

Can your tell me what can be wrong ? As I have my page in utf-8 and the sql is well formed in my  debug echo($sQuery); (at least on screen)

 

 

 

Thanks

Robert

Link to comment
https://forums.phpfreaks.com/topic/109864-search-mysql-to-support-utf/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.