数据库技术   

高效解决PHP+MYSQL出现乱码的方法

时间:2011-06-01 09:12:00

 在使用PHP+MYSQL时,您是否遇到过字符乱码的问题呢?您是如何解决这个问题的呢?这里提供了一种解决之道。

使用PHP+MYSQL时遇到过字符乱问题,解决方法:

  在mysql_connect后面加一句SET NAMES UTF8,即可使得UTF8的数据库消除乱码,对于GBK的数据库则使用SET NAMES GBK,代码如下:

  1 $mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 2 mysql_query("SET NAMES "GBK");

  数据库字符集为

  连接语句用这个

  1 mysql_query("SET NAMES "UTF8"); 2 mysql_query("SET CHARACTER SET UTF8"); 3 mysql_query("SET CHARACTER_SET_RESULTS=UTF8");

 

来源:PHPchina

Notice: Constant RUNTIME already defined in /srv/html/srccn/news/config.php on line 15 Notice: Constant ROOTDIR already defined in /srv/html/srccn/news/config.php on line 16 Notice: Constant SITEDIR already defined in /srv/html/srccn/news/config.php on line 17 Notice: Constant DATAURL already defined in /srv/html/srccn/news/config.php on line 20 Notice: Constant VERSION already defined in /srv/html/srccn/news/system/kernel.php on line 17 Notice: Constant COREDIR already defined in /srv/html/srccn/news/system/kernel.php on line 18 Fatal error: require(): Cannot redeclare class mysql in /srv/html/srccn/news/system/kernel.php on line 22