Reputation: 302
I'm trying to store an Arabic text to the table, I searched a lot but I didn't find a solution that worked for me, so this is what I got:
$en = "OK";
$ar = "حسناً";
$link->query("INSERT INTO words (en,ar) VALUES ($en,$ar)");
The problem is when I insert it, the Arabic text looks like Øسناً
, my table's collation and MySQL's are utf8_general_ci
, so is my database's, I also have mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
, but it doesn't work.
Upvotes: 6
Views: 12527
Reputation: 49
Here is a solution that worked for me:
when you create the database choose the collation for: utf8_unicode_ci
when you connect to the database from php use the following character set:
$dsn = "mysql:host=localhost;dbname=record;charset=utf8";
Upvotes: 0
Reputation: 24949
First thing is the database, table, and column. See if utf8
is set:
utf8_general_ci
or utf8_unicode_ci
Also, the connection collation: utf8_general_ci
In PHP, after I connect with mysqli, I issue this:
$conn->query("SET NAMES 'utf8'");
And the web page output always jams in:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Upvotes: 4
Reputation: 26450
I recently had the same issues myself.
Here's a few pointers:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and PHP: header('Content-Type: text/html; charset=utf-8');
$link->set_charset("utf8");
(directly after connecting)ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Remember that EVERYTHING needs to be set to UFT-8 charcode, or else it'll insert stuff like "Øسناً". Hope this helped!
Upvotes: 12