Hi; I have iso-8859-9 records in my mysql database and i want to convert them to utf8. But i dont know how to do that? Can anybody help me? Thanks
Try running this query before pulling the data: mysql_query("SET NAMES utf8") OR die(mysql_error()); PHP:
$link = mysql_connect("localhost", "user", "pass"); mysql_select_db("db_name", $link); if ( ! mysql_select_db("db_name", $link)) die ("MySQL connection problem!"); mysql_query("SET NAMES utf8") OR die(mysql_error()); $result = mysql_query("select title,introtext,metakey,metadesc,sectionid,catid from `jos_content2` LIMIT 10", $link); while ($row = mysql_fetch_assoc($result)) { $title=$row['title']; $introtext=$row['introtext']; $metakey=$row['metakey']; $metadesc=$row['metadesc']; $sectionid=$row['sectionid']; $catid=$row['catid']; $title=iconv("ISO-8859-9", "UTF-8",$title); $introtext=iconv("ISO-8859-9", "UTF-8",$introtext); $metakey=iconv("ISO-8859-9", "UTF-8",$metakey); $metadesc=iconv("ISO-8859-9", "UTF-8",$metadesc); $sectionid=iconv("ISO-8859-9", "UTF-8",$sectionid); $catid=iconv("ISO-8859-9", "UTF-8",$catid); $insert= mysql_query("insert into jos_content (`title`,`introtext`,`sectionid`,`catid`,`publish_up`,`created`,`created_by`,`version`,`state`,`metakey`,`metadesc`) values ('$title',' $introtext','$sectionid','$catid',NOW(),NOW(),'1','1','1','$metakey','$metadesc')"); echo $title . "<br/>"; echo $introtext . "<br/>"; echo $metakey . "<br/>"; echo $metadesc . "<br/>"; echo $sectionid . "<br/>"; echo $catid . "<br/>"; } Code (markup): my code is above. if i want to print the results to screen , it works but when i check the results in db. it did not worked. jos_content2 is latin1 and jos_content is uft8. what's the problem with my code? Regards