发现了一个解决方法,就是在mysql_connect后面加一句SET NAMES UTF8,即可使得UTF8的数据库消除乱码,对于GBK的数据库则使用SET NAMES GBK,代码如下:$mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_query("SET NAMES 'GBK'");
------------------------------------------
相关帖子: http://briteming.blogspot.co.uk/2012/02/phpmysql.html
mysql_query("SET NAMES 'GBK'");
------------------------------------------
解决PHP链接MySQL数据库乱码
PHP代码:
1
2 3 4 5 6 7 8 |
$connection=mysql_connect ($localhost, $username, $password);
mysql_query('SET NAMES utf8');//根据php文件编码设置链接编码 //gbk的话 //mysql_query('SET NAMES gbk'); $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } |
相关帖子: http://briteming.blogspot.co.uk/2012/02/phpmysql.html