{"id":326,"date":"2011-08-19T14:35:00","date_gmt":"2011-08-19T12:35:00","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=326"},"modified":"2013-05-24T22:11:17","modified_gmt":"2013-05-24T20:11:17","slug":"php-mysql-utf8-arabic-insertion-balises-php","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=326","title":{"rendered":"PHP Mysql UTF8 arabic CRUD database"},"content":{"rendered":"<p>To read ,write and sort Arabic text in mysql database using php correctly, make sure that:<\/p>\n<p>1- MySQL charset: UTF-8 Unicode (utf8)<br \/>\n2- MySQL connection collation: utf8_general_ci<br \/>\n3- your database and table collations are set to: utf8_general_ci or utf8_unicode_ci<\/p>\n<p>Then, add this code in your php database connect script :<\/p>\n<p>mysql_query(&#8220;SET NAMES &#8216;utf8&#8242;&#8221;);<br \/>\nmysql_query(&#8216;SET CHARACTER SET utf8&#8217;);<\/p>\n<p>For Example :<\/p>\n<pre>function connect() \/* {{{ *\/\r\n{\r\nif (isset($this-&gt;dbh)) {\r\n\r\nmysql_query(\"SET CHARACTER SET 'utf8'\", $this-&gt;dbh);\r\nmysql_query(\"set names utf8 \", $this-&gt;dbh);\r\nmysql_query(\"SET NAMES 'utf8'\");\r\nmysql_query('SET CHARACTER SET utf8');\r\nreturn true;\r\n}\r\n\r\n<\/pre>\n<h2>Create an UTF8 mysql databases<\/h2>\n<p>Create an unicode database with the collation utf8_ci_general :<\/p>\n<pre>\r\nCREATE TABLE `t1_test` (\r\n`c1_utf8` varchar(50) character set utf8 default NULL,\r\n`c2_eng` varchar(50) default NULL\r\n) ENGINE=MyISAM DEFAULT CHARSET=latin1;\r\n\r\n--\r\n-- Dumping data for table `t1_test`\r\n--\r\n\r\nINSERT INTO `t1_test` VALUES ('\u0643\u064a\u0641 \u0627\u0644\u062d\u0627\u0644', 'test2');\r\n<\/pre>\n<p>To have the right display for arabic under your browser for a unicode database :<br \/>\nIn case of a PHP APACHE script:<\/p>\n<pre>\r\n&lt;?php header(\"Content-Type: text\/html; charset=utf-8\"); ?&gt;\r\n<\/pre>\n<p>In case of an HTML page :<\/p>\n<pre> \r\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;\r\n<\/pre>\n<p>Now you can create a small script to test the output or go directly in phpmyAdmin.<br \/>\nCheers,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To read ,write and sort Arabic text in mysql database using php correctly, make sure that: 1- MySQL charset: UTF-8 Unicode (utf8) 2- MySQL connection collation: utf8_general_ci 3- your database and table collations are&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2845,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[35,26,182],"tags":[117,180,181],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2845"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}