TP 框架解决Unknown column 'XXX' in 'where clause' 问题

最近在使用TP框架开发公司网站,遇到了一个问题Unknown column 'XXX' in 'where clause'的问题。

这个问题最初查询用户的个人信息,分别通过用户的手机号和邮箱查询:

1.手机号查询

$mobile = (string)'手机号XXX';

$user = M('ey_user')->where('phone='.$mobile)->find();

var_dump($user);

可以查询出数据。

2.邮箱查询

$mobile = (string)'[email protected]';

$user = M('ey_user')->where('phone='.$mobile)->find();

var_dump($user);

查询的结果:


我怀疑是由于TP框架或者是Mysql对于‘@’有什么特殊编码要求,然而并不是。我尝试使用数字和字符串查询,数字没有问题,但是字符串就会出现问题。

根据对打印出来的bug定位,分别对框架中的代码,进行分析最终打印“Driver.class.php  LINE: 352”数据库的代码。


打印结果是“Unknown column 'XXX' in 'where clause”。

针对Mysql 出现“Unknown column 'XXX' in 'where clause”错误,存在两个种可能出现错误的原因:

1)数据库的数据表种“ column 'XXX' ”不存在,但是这种情况一般很少会出现。

****2)数据库无法识别“XXX字符串”,无法正确解析字符串。所以我们要把查询的内容转化成字符串类型**********

$mobile = (string)'[email protected]';

$user = M('ey_user')->where('phone=\''.$mobile.'\'')->find();

var_dump($user);

在字符串上添加单引号,使用String并没有什么效果。


Unknown column 'XXX' in 'where clause:

      1)检查字符串添加单引号,转化成字符串类型(Mysql无法解析模糊的类型)

      2)检查数据库的表中是否存在xxx的行


有什么问题和不同的意见欢迎留言讨论

猜你喜欢

转载自blog.csdn.net/Future_One/article/details/80836588
今日推荐