mysql结果返回?(问号)而不是Ö等 [英] mysql result returns ?(question mark) instead of Ö etc

查看:95
本文介绍了mysql结果返回?(问号)而不是Ö等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从mySQL数据库返回一行时,得到一个?而不是某些字符,例如:ò,à 等等.我的mysql行和表设置为utf8_unicode_ci,所以我认为数据库正确存储了它,但是php没有正确返回它.

When i return a row from my mySQL database, I get a ? instead of some characters eg:ò, à etc. My mysql row and table are set to utf8_unicode_ci, so I think the database is storing it correctly but php isnt returning it correctly.

认为它与mysql_set_charset有关,但无法使其正常工作.任何帮助将不胜感激!

Think it has something to do with mysql_set_charset but cant get it to work properly. Any help would be greatly appreciated!!

  <?php 
if($row = mysql_fetch_assoc(queryDb("SELECT * FROM customer WHERE uuid='".$_COOKIE['uuid']."'")))
 {
  $first_name = $row['first_name'];
  $last_name = $row['last_name'];
  $gender = $row['gender'];


  $ileach_first_name = $row['ileach_first'];
  $ileach_last_name = $row['ileach_last'];

}

 //If Ileach Name is blank

  if($ileach_last_name == "" || $ileach_first_name == ""){


  // Get ileach last name
  $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_last_names WHERE eng_name='$last_name'"));

  $ileach_last_name = $row['gae_name']; 


  if($ileach_last_name == "") {
     $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_last_names order by rand() limit 1"));
    $ileach_last_name = $row['gae_name'];}  



  //Get ileach First Name
   //If Male
    if($gender == 'M') {

     $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_first_names_m WHERE eng_name='$first_name'"));

     $ileach_first_name = $row['gae_name']; 

     //If no name is selected, get one randomly 
      if($ileach_first_name == "") {
       $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_first_names_m order by rand() limit 1"));
     $ileach_first_name = $row['gae_name']; }
    }
   //If Female 


    else{

     $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_first_names_f WHERE eng_name='$first_name'"));

     $ileach_first_name = $row['gae_name']; 

     //If no name is selected, get one randomly 
     if($ileach_first_name == "") {
       $row = mysql_fetch_assoc(queryDb("SELECT * FROM ileach_first_names_f order by rand() limit 1"));
     $ileach_first_name = $row['gae_name'];}
    }




  //Save ileach name into db

   mysql_query("UPDATE customer SET ileach_first = '$ileach_first_name'
   WHERE uuid='".$_COOKIE['uuid']."' ");

   mysql_query("UPDATE customer SET ileach_last = '$ileach_last_name'
   WHERE uuid='".$_COOKIE['uuid']."' ");
  }


  //Stitch name together.

  $full_ileach_name .=$ileach_first_name;
  $full_ileach_name .= " ";
  $full_ileach_name .= $ileach_last_name;





?>

推荐答案

认为它与mysql_set_charset有关"-是的,很有可能.

"Think it has something to do with mysql_set_charset" - yes, very likely.

$mysql = mysql_connect(...); // TODO: error handling
mysql_select_db('...', $mysql);  // TODO: error handling
mysql_set_charset('utf8', $mysql);  // TODO: error handling

要获取更多详细信息,我们需要更多地了解函数queryDB()和相关内容(例如建立数据库连接的地方)

For mor detailed information we need to know more about the function queryDB() and related stuff (like e.g. where the database connection is established)

另请参阅:

  • http://dev.mysql.com/doc/mysql/en/charset-connection.html
  • http://docs.php.net/mysql_set_charset

这篇关于mysql结果返回?(问号)而不是Ö等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆