PHP中文字符无法插入到Mysql [英] PHP Chinese Characters Can't Insert To Mysql
问题描述
我使用GET传递参数,如果数据是英文,则成功保存数据到mysql,但如果数据是中文,则没有插入。
I am using GET to pass parameters, succesful save data to mysql if the data is in english, but nothing insert if the data is in chinese.
检测到数据编码是utf-8,发现使用我的macbook它工作正常,但不工作ie。奇怪,任何想法有什么问题吗?
I have detected the data encoding is utf-8, found out that using my macbook it works fine, but not working on ie. Strange, any idea what's wrong with it?
例如
query("insert into Info values ('".$email."','".$_GET['name']."')");
如果 $ name
。我已经尝试了 echo $ _GET ['name']
并且正常显示,数据无法插入到数据库中是空白的。
This not successful if $name
is chinese. I have tried echo $_GET['name']
and display normally, howerver the data can't inserted to databse is blank.
query("insert into Info values ('".$email."','香港')");
此方法成功将数据插入数据库
This method successful insert data to database
推荐答案
首先,你应该为这些操作使用POST。
Firstly, you really should use POST for these operations.
检查以确保您插入的列具有正确的
Check to ensure that the column you are inserting into has the correct encoding - perhaps export the table structure for us to see if you're not sure.
正如Daan所说,你可以尝试
As Daan said, you could try
query('SET NAMES UTF8');
在插入查询之前。
这篇关于PHP中文字符无法插入到Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!