Home >Backend Development >PHP Tutorial >新手刚学PHP,问个SQL插入语句中文乱码的有关问题

新手刚学PHP,问个SQL插入语句中文乱码的有关问题

WBOY
WBOYOriginal
2016-06-13 10:23:56762browse

新手刚学PHP,问个SQL插入语句中文乱码的问题。

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php @mysql_connect("localhost", "root", "") or die("连接MySQL数据库失败。");mysql_select_db("test") or die("打开MySQL数据库失败。");$sql = "INSERT INTO test (id, uid, regdate, remark) VALUES('', '测试', now(), '测试')";mysql_query($sql);?>


问:中文就是乱码,英文正常,怎么办呀?PHP版本是5.3.8,MySQL版本是5.5.16,各位好汉帮帮忙~~~

------解决方案--------------------
mysql_query("set names gbk");
另外,你的文件编码也要改为gbk编码。
------解决方案--------------------
探讨

引用:

统一编码。插入前执行:mysql_query("set names '你的数据表编码'");

我的数据表编码:是gbk_chinese_ci
我把代码改成:
PHP code
@mysql_connect("localhost", "root", "") or die("连接MySQL数据库失败。");
mysql_select_db(……
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn