PHP PDO数据库错误特殊字符 [英] PHP PDO Database Error Special Characters

查看:69
本文介绍了PHP PDO数据库错误特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关这种情况的大多数问题和答案,但是我无法解决我的性格问题.我数据库的默认字符集是utf8,所有表的排序规则是utf8_general_ci.我确定所有设置都是utf8和utf8_general_ci,因为我已经检查了数十亿次.问题是在表单中发布值后,它似乎不像我想要的数据库,而且如果我从phpmyadmin编辑数据库,则当我获取数据时,它再次没有显示我想要的.

i've read most of the questions and answers about this situation but i cant fix my character problem. My database's default character set is utf8 and all the tables' collation is utf8_general_ci. I'm sure that all of the settings are utf8 and utf8_general_ci, cuz i've checked them billions of time. Problem is after posting the value within a form, it doesnt seem like what i want in database, and also if i edit the database from phpmyadmin, when i fetch the data, its again not showing what i want.

DB连接有效,我像以前提到的那样编辑了这种情况,但是我的脚本在字符指定方面有很多问题.

The DB connection works, i edited it like mentioned before about this situation, but my script is buggy about character speciziliation..

数据库连接代码为:

try {

$db = new PDO("mysql:host={$db_server};dbname={$db_name};charset=utf-8", $db_user, $db_password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
// exc 
}

如果能提供帮助,我们将很高兴

Would be glad if you can help

致谢

推荐答案

对于那些具有相同错误的人,即使您也确定@zerkms提到的内容:

For those who has the same error even you are sure about the things that @zerkms mentioned :

您需要使用相同的编码:1)页面/表单2)表和列(如果有的话)字符集(不归类)3)db连接.就是这样.如果所有3个都相同utf-8-那么它应该可以工作.如果不能,则-您缺少了某些东西,需要重新检查它们中的每个"

" you need to have in the same encoding: 1) the page/form 2) table and column (if any) charset (not collation) 3) db connection. That's it. If you have all 3 of them the same utf-8 - then it should work. If it doesn't - you're missing something and need to re-check each of them "

如果您仍然像我一样遇到问题,请检查您的表单处理数据,看看是否有忘记的过滤器.我有一个用于安全性的过滤器,它正在过滤输入,并且仅用于ANSI编码,因此请检查所有内容,然后再进行检查.

if you are still having problem like i did, check your form process data that if there is a filter that you forgot. i had a filter for security, it was sanitizing inputs and it was only for ansi encoding, so check out everything and than it will be fine.

感谢所有答复.

这篇关于PHP PDO数据库错误特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆