For almost a month I am trying to display urdu, arabic and punjabi in yiiframework, but failed.
The words to display in these languages are coming from mysql database.
In previous code, using the same database, everything is working fine. That means, my browser and server is able to display unicode (UTF-, and mysql table is also set to have UTF-8.
Here is a working example of what I have
901
However using yii, I cannot have the desired output.
I have also changed the CStringValidator encoding="UTF-8" from "false", but to no avail.
Here is what I am getting in yii
902
Please note that, even at the time of capturing the images, both old and yii based codes are using the same database, and not to mention the server and operating system.
Can you test if the output from Yii php scripts works - just put echo "your characters" somewhere in the view… just to see if the problem is only with the data read from the database…
Thanks for the line, I think now we are getting somewhere
The simple echo works fine, and I tried to store the same words in a variable and echoed it also, works too.
The reduces the problem to either Mysql Database output, or the yii’s stringvalidator class.
To Cut it short, my phpmyadmin (browser based) and mysql query browser (separate GUI), both are unable to show the characters and behaves much like yii. However, what confuses me, if both of them ( and including yii make them 3) cannot display the characters, how can my old script is still doing it from the same database at the same operating system and using the same web server?
p.s.: I am using windows 7 (IIS 7.5) and ubuntu 10.10 (apache2) dual boot, using single location for database and web root for both of them, i.e. I don’t have to copy files to other location to access the website in either os.
Ok, thanks for this advice also, I have tried that, and used a simple mysql_query function placed inside the SiteController’s actionIndex and passed the result to index.php in views->site and iterated them, working fine and displaying the results accurately in different unicode languages.
Whats next?
I think the problem lies either in mysql object of yii, or the CStringValidator.
I remember these kind of problems and the reason for me always was a mismatch in DB encoding. For example it could be that when you initially wrote your data to DB, the connection charset didn’t match the table charset. Then lot of things can happen. For me i wasn’t able to get anything useful back, except using the same wrong connection encoding when reading the data. If i remember well, my connection used ISO-8859-1 even though my DB table was UTF-8. So i always had to use ISO-8859-1 for the connection (and only there!) to get something useful back.
The only way out: If you somehow manage to get the data out correctly (which you say you can with your old script), try what i suggested in step 2. in the cookbook you mentioned: Try to export your data into a text file and carefully check that file’s encoding (using a good editor, maybe try different ones). Then double check again that all charsets are UTF-8 (File encoding, CREATE statements and DB Connection) and import the data back.
Thanks Mike, You are so right, the problem was not in fetching the data, it was in storing, simply removing the line ‘charset’=>‘utf8’ solved the problem and the data is now displayed very accurately.
The reason is the same you mentioned, before yii, I never checked what is the connection type of mysql.
Well, Changing the whole data from latin-1 to utf8 is quite a lot of work, and in future I am planning to do so.
Thanks for your valuable help, finally I can now use yii for multiple purposes.
I am planning to convert oscommerce to yii, does anyone has any idea is this work has started already?
I don’t think anyone is working on a port of oscommerce, that’s a very ambitious plan. Even though it would surely be very cool to have such a full featured shop system written in Yii.
I am having the same issue with Arabic from my database. If I comment out the ‘charset’=>‘utf8’ line in the config then things are fine! Is it OK to leave it like this? What are the potential problems?
I know, I know. I’m being a totally lazy developer! But as the saying goes, if it aint broken, don’t fix it!
Answer: In Mysql, storing UTF-8 string in a non-utf-8 table (usually latin or swedish).
In my case, the charset of mysql table was set to utf-8 (very correct), but the charset of the actual column was WESTERN-ISO-8859 (used for English, German, French, Swedish and so on).
Solution: Check the mysql table and column, store them properly.
However I am still having the problem in getting my data out of mysql using phpmyadmin/mysql gui. because mysql gui is showing ?? and phpmyadmin some crappy characters.
The only way I have, which is a tedious one, is to write my own script using yii to generate sql statements, save the script in utf-8 and re-upload it.