I am facing an small issue in my project When I am trying to store some German words into the MYSQL Database. When this German words contains umlauts i.e. characters ä, ö, ß, ü etc., they are not stored as they are.....?
I want to store them as it is into the Database.To do so I tried to change the COLLATION to UTF8-general-ci, and others in the list using PHP myAdmin
. But none of them is working for me.
Am I in the right way or I have to do something else.
Please suggest some help.
Thanks In Advance......
years ago I've faced the same problem. I've solved it by implicit setting NAMES option for mysql. In my code it looks like this:
//inside AbstractMapper class
public function __construct($modelClass, $dbTable) {
$this->setDbTable($dbTable);
$stmt = new Zend_Db_Statement_Pdo($this->getDbTable()->getAdapter(), 'set names utf8');
$stmt->execute();
$this->_model_class = $modelClass;
}
You have to choose the right transfer encoding either. Call
SET NAMES utf8
before inserting the data and make sure that the german words are utf8-encoded before inserting.
Try to use utf8_encode($string) to encode your text into UTF8 first, before saving it into the database. In order for characters to display correctly in a certain language, you have to (1) set the text into the right charset and then also (2) set a database to the right charset (as you did).
Also, for example, file display.php
will output the German text, you can open the file in any editors (EmEditor?) and then "save as", choose a right encoding scheme. After that, the display file, when outputting the text, will take care of the charset.
After connecting to the database, use the following codes:
SET NAMES XXX
replace XXX with your working charset.