我的 mysql 插入语句有问题。
我有一个将 utf-8 字符正确提交到插入文件的表单(我已经检查了 POST 变量)。
现在,当我查看数据库中的 INSERT 时,没有变音符号,而是问号。
该错误必须位于插入语句之前。
如果我从数据库输出(手动输入)内容,元音变音会正确显示。
// echo $_POST["title"];
// outputs correctly with special chars: "Some german title with umlaute ä ö ü"
mysql_query("INSERT INTO videos (youtube_hash, title, description, category, created) VALUES ('".mysql_real_escape_string($_POST["hash"])."', '".mysql_real_escape_string($_POST["title"])."', '".mysql_real_escape_string($_POST["desc"])."', '".mysql_real_escape_string($_POST["cat"])."', '".time()."')") or die(mysql_error());
// database entry looks like this: "Some german title with umlaute ? ? ?"
我希望任何人都可以帮助我:)
EDIT:
htmlentities() 完成了这项工作!
当您将 php 中的数据插入 mysql 数据库时,尝试使用 utf8_decode() 包装字符串数据;
utf8_decode(string)
正如 php 手册所说,这会将 utf8 转换为 ISO-8859-1 (latin1);
您可能还想尝试一下iconv() http://www.php.net/manual/en/function.iconv.php功能。
这使您可以更多地选择输入编码和所需的输出编码
string iconv ( string $in_charset , string $out_charset , string $str )
如果仍然没有帮助,请尝试将要插入的 Mysql 表列上的排序规则更改为 latin1_swedish_ci。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)