Re: Arabic text in mysql Varchar row
Posted by:
Mark Webley ()
Date: September 08, 2011 04:45PM
Hello Rick
Thank you for your response.
For the query "HOW CREATE TABLE user" I see:
user | CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`description` longtext,
`country` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`,`country`)
) ENGINE=MyISAM AUTO_INCREMENT=253 DEFAULT CHARSET=utf8 |
I was reading some of the information on that link you mentioned previously,
I did a test and changed the PHP db insert for the 'title' and 'company'
with an example of Arabic text, the procedure insert uses utf8_encoding like:
"Call procedureName(\"". utf8_encode($title) . "\",
\"" . utf8_encode($company) . "\",
\"$description\")"
The 'description' text in the Database display normally as Arabic text without any like garbage looking text.
In the database the other column named 'text' the Arabic text insert looks like:
Ù? اÙ?خط ÙÙ? اÙ? ÙÙ? اÙ?خط ÙÙ? اÙ? ÙÙ? اÙ?خط
WHen I echo this back to the page for the title and company I it seams to look
better because I now echo with PHP's:
nl2br(utf8_decode($title))
but I get Square symbols and '?' mixed in with the Arabic text (but I am not
sure if the Arabic text is right) which is shown as:
�? ا�?خط ف�? ا�? ف�? ا�?خط ف�? ا�? ف�? ا�?خط
(Note: where it is cut and pasted above, you see "�" is where I see square symbols)
With the other column 'description' I do not have to do anything it works fine I just php echo nl2br($description) and it comes out great.
....do I have to change my.cnf somewhere on my Local HD?
I did a test from reading some of that link you sent above with:
SELECT title, HEX(title), LENGTH(title), CHAR_LENGTH(title) FROM ... WHERE ... LIMIT 1
and I see:
+----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+-----------------------+
| title | HEX(title) | LENGTH(title) | CHAR_LENGTH(title) |
+----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+-----------------------+
| Ù? اÙ?خط ÙÙ? اÙ? ÙÙ? اÙ?خط ÙÙ? اÙ? ÙÙ? اÙ?خط | C3993F20C398C2A7C3993FC398C2AEC398C2B720C399C281C3993F20C398C2A7C3993F20C399C281C3993F20C398C2A7C3993FC398C2AEC398C2B720C399C281C3993F20C398C2A7C3993F20C399C281C3993F20C398C2A7C3993FC398C2AEC398C2B720 | 100 | 60 |
+----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+-----------------------+
What do you think?...I will continue reading that link....
Thanks again...