解决在ajax进行交互的时候,返回的是乱码,比如????????????这样的记录的解决方法

mysql_query("SET NAMES 'GBK '") or die(error(mysql_error()));

 

 

$db = new mysqli('192.168.200.254', 'dxy' ,'p0o9i8u7', 'patent'); if(!$db) { // Show error if we cannot connect. echo 'ERROR: Could not connect to the database.'; } else { // Is there a posted query string? if(isset($_POST['queryString'])) { $queryString = $db->real_escape_string($_POST['queryString']); // Is the string length greater than 0? if(strlen($queryString) >0) { $db->query("SET CHARACTER SET utf8"); $query = $db->query($query = "select patent_id,patent_name from list_id where patent_id like '%$queryString%' limit 6"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { echo "<li onClick=fill('".$result->patent_id."^^^".$result->patent_name."');>".$result->patent_id."<br/>".$result->patent_name."</li>"; } } else { echo 'ERROR: There was a problem with the query.'; } } else { // Dont do anything. } // There is a queryString. } else { echo 'There should be no direct access to this script!'; } }

 

 

你可能感兴趣的:(mysql,Ajax,object,String,query,character)