March 29 2014

PHP how to insert Chinese character into MySQL

Tagged Under : ,

php
The way to insert Chinese character into MySQL table. You need set the table structure charset to utf8.
CREATE TABLE IF NOT EXISTS `contents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
After that, add the following code as below:
mysql_connect(HOST, USER, PASSWORD);
mysql_select_db(DBNAME);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER_SET_CLIENT=utf8");
mysql_query("SET CHARACTER_SET_RESULTS=utf8");

Make a Comment

*

code