Like dinok said,
If I use $dbquery("SET NAMES 'utf8'");
I have it working.

But does that still means I have garbage in my db ?

Concretely I am storing the countries with their respective ISO code from a
.csv file in my DB.
The .csv file is UTF-8 with BOM encoded. The source file of this script is
UTF-8 encoded and the DB is UTF8 encoded (it shows "utf8", not "utf-8").

  $fcontents = file ('C:/toImport.csv'); 
  for($i=0; $i<sizeof($fcontents); $i++) { 
          $line = trim($fcontents[$i]); 
          $arr = explode(";", $line); 
          $arr[0] = addslashes ( ucwords ( mb_strtolower( $arr[0] , "utf-8" ) ) 
);
          $sql1 = "SET NAMES 'utf8'";
          $sql2 = "insert into countries (iso, country) values ('" . $arr[1] .
"','" . $arr[0] ."')"; 
          mysql_query($sql1);
          mysql_query($sql2);
          echo $sql2 ."<br>\n";
          if(mysql_error()) {
                 echo mysql_error() ."<br>\n";
          } 
  }



Michael B Allen-3 wrote:
> 
> On 10/14/07, debussy007 <[EMAIL PROTECTED]> wrote:
>>
>>
>> * My MySQL database is UTF-8 encoded,
>> * all my source pages are UTF-8 encoded,
>> * I have the following meta-tag :
>>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>>    (I can confirm with FF Web developer Toolbar that the rendered page is
>> encoded in utf-8)
>> * I added $this->view->setEncoding('UTF-8'); in the predispatch method
>> inherited by all my controllers,
>>
>> But when I want to display the list of countries I have in my MySQL DB,
>> I still have those weird characters. E.g. for country "Côte d'Ivoire"
>> I cannot see the letter ô but a weird character instead.
> 
> Even if the DB is set to use UTF-8 you can still put invalid UTF-8 in
> string fields. If you put gargbage in you get garbage out. That will
> happen if, for example, the form used to submit the data was not
> rendered using UTF-8. Meaning, at the time you submitted the data you
> application didn't handle UTF-8. Fix your app, delete those records
> and try again.
> 
> Mike
> 
> -- 
> Michael B Allen
> PHP Active Directory SPNEGO SSO
> http://www.ioplex.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Best-place-to-specify-encoding-tf4621717s16154.html#a13199938
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to