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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.