I am trying to export data from mysql database to a CSV file, but Thai content is being displayed as ????s. Also, in database it's not taking whatever I enter. If I enter ปดิวรัดา , it's saving as ปดิวรัดา
Please help me.
EDIT: Now, i edited encoding of table and fields to utf8_general_ci and its storing data as i entered into database but still export problem exists.
Original code we have written is here
Set your database encoding to utf8_general_ci
Also check that your column with strings has encoding utf8_general_ci.
Add this to the beginning if the $buffer you're exporting:
$buffer = chr(239) . chr(187) . chr(191) . $buffer;
The encoding is UTF with BOM, adding this will add the BOM.
Related
I am doing migration to generate SQL from one DB to another.
I am trying to get the output
But when I did a mb_convert_encoding("Mr.Wang (王老板)", 'UTF-8', 'Windows-1252')
I have the output as
I have those two extra "box". Any idea what am I doing wrong?
phpMyAdmin is able to export my old database containing chinese text in correct format, how do it do that in script?
*updated the images to better show my view
Have you tried setting the header in the script to UTF8? What I normally use is the following:
header('Content-Type: text/html; charset=utf-8');
That has worked for me so far for German characters & some Arabic & Japanese etc.
I found that I actually need to
mysql_query("SET NAMES 'utf8'");
before my select statement. And I do not need to run mb_convert_encoding("Mr.Wang (王老板)", 'UTF-8', 'Windows-1252') at all.
Now if I write my insert sql I got the correct text i wanted.
I have a site developed in codeigniter where I'd like to insert a record inside my database in a table with utf8 fields.
The problem is that when I insert something inside the table I see that:
�"�h�t�t�p�:�/�/�I�m�a�g�e�1�.�u�r�l�f�o�r�i�m�a�g�e�s�.�c�o�m�/�D�e�f�a�u�l�t�/�8�8�0�4�/�2�3�6�9�2�2�6�2�-�1�8�4�3�3�8�5�2�6�6�.�j�p�g�"�
There are many more characters. The real string is a simple path. I don't know the format of the string because it is from an external server.
This is my query to insert record. I take the string from xml and if I print it inside the page I see the correct string. The problem occurs whenever I check inside the database:
foreach($img->childNodes as $node){
$data = array(
'image'=>$node->getAttribute('path'),
);
$this->db->insert('hotel_images',$data);
}
That data is not UTF-8. It is UCS-2 or UTF-16. UCS-2 is a subset of UTF-16, so treating it as UTF-16 should do the trick.
You can convert it using iconv.
$data = iconv("UTF-16", "UTF-8", $data);
I am trying to save a string in database and get something like this
Период д

The string that I want to save : Период действия S...
The table encoding is: cp1251_general_ci
I don't know in which encoding the string is - I am getting it from an excel document.
I tried this, but it didn' help.
$nomer = iconv('UTF-8','Windows-1251', $str );
Is there a solution for this?
You haven't mentioned the database engine you're using, but try changing the table encoding to something like utf8_general_ci or utf8_unicode_ci.
this might look like a similar issues for utf8 and Arabic language with MySQL database but i searched for result and found none..
my database endocing is set to utf8_general_ci ,
i had my php paging to be encoded as ansi by default
the arabic language in database shows as : ãÌÑÈ
but i changed it to utf8 ,
if i add new input to database , the arabic language in database shows as : زين
i dont care how it show indatabase as long as it shows normally in php page ,
after changing the php page to utf8 , when adding input than retriving it , if show result as it should .
but the old data which was added before converting the page encoding to uft8 show like this : �����
i tried a lot of methods for fixis this like using iconv in ssh and php , utf8_decode() utf8_encode() .. and more but none worked .
so i was hoping that you have a solution for me here ?
update :: Main goal was solved by retrieving data from php page in old encoding ' windows-1256' than update it from ssh .
but one issue left ::
i have some text that was inserted as 'windows-1256' and other that was inserted as 'utf-8' so now the windows encoding was converted to utf-8 and works fine , but the original utf-8 was converted as well to something unreadable , using iconv in php, with old page encoding ..
so is there a way to check what encoding is original in order to convert or not ?
Try run query set name utf8 after create a DB connection, before run any other query.
Such as :
$dbh = new PDO('mysql:dbname='.DB_NAME.';host='.DB_HOST, DB_USER, DB_PASSWORD);
$dbh->exec('set names utf8');
I'm having an issue with exporting data from a utf8 mysql database into an excel sheet with PHPExcel and retaining chinese characters. My mysql db is utf8 and has numerous chinese characters in it, and I'm exporting that data into a multi-sheet xls file (excel5) and every export the chinese characters turn into "?". I've tried utf8_encode() but it doesn't work for me. I also tried changing the output to excel2007 thinking it would be an excel5 writer issue.
Is there a way to get Chinese characters to export correctly?
Do I have to make the entire php file utf8? and if so how would I go about doing so?
Here is the portion I'm having issue with:
$res2 = mysql_query("SHOW COLUMNS FROM ".$sheetnametemp);
while($row2 = mysql_fetch_array($res2, MYSQL_NUM)) {
$counter = 2;
$cell = $coltemp;
$cell .= $counter;
$objPHPExcel->getActiveSheet()->SetCellValue($cell, $row2[0]);
$result = mysql_query("SELECT * FROM ".$sheetnametemp);
while($row = mysql_fetch_array($result))
{
$counter++;
$cell2 = $coltemp;
$cell2 .= $counter;
utf8_encode($row[$row2[0]]);
echo "<br />";
$objPHPExcel->getActiveSheet()->SetCellValue($cell2,utf8_encode($row[$row2[0]]));
}
I need to use those chinese characters as it is a multi-lingual catalog db so changing it to english wouldn't help. Also I am currently on a Mac with Xampp if that info is helpful in anyway.
Setting your executing "SET NAMES utf8" or mysql_set_charset("UTF8", $conn); to ensure that your connection to the database is using UTF-8.
You can test the connection using echo mysql_client_encoding($conn);
Make sure that you're not trying to call utf8_encode() anymore either.
Note: An Excel file uses a codepage to identify the character set being used within the file, but PHPExcel sets that codepage to a hard-coded value of UTF-8 internally, so all string content in the file should be UTF-8, and Excel knows to interpret the worksheets in the MS Excel GUI as UTF-8 as well. If you're not seeing chinese characters when you look at the spreadsheet in Excel itself, then check the language settings in MS Excel to see if it's configured to handle chinese
Credit: #Mark Baker.
Thanks again.