Doctrine Query Where 子句产生的未知列错误
我有以下查询:
return Doctrine_Query::create()
->from('Model_Article m')
->where($where)
->orderBy($order);
在 $where
中我有这个:
$where='m.title='.$name;
上面产生了这个错误:
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sadsa' in 'where clause'. Failing Query: "SELECT COUNT(*) AS num_results FROM article a WHERE a.title = sadsa"
为什么?
I have the following query:
return Doctrine_Query::create()
->from('Model_Article m')
->where($where)
->orderBy($order);
In $where
I have this:
$where='m.title='.$name;
The above produces this error:
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sadsa' in 'where clause'. Failing Query: "SELECT COUNT(*) AS num_results FROM article a WHERE a.title = sadsa"
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是因为结果查询看起来像“** where title=sadsda **”,因此 SQL 引擎查找名为“sadsda”的列。为了防止这种情况,您必须提及,您要与字符串而不是列值进行比较。您可以使用您的引擎规则(通常用“'”括起字符串)来实现它,但它不安全,我认为您应该使用占位符引擎,该学说提供了例如
Error is because resulting query looks like "** where title=sadsda **", so SQL engine looks for column named "sadsda". To prevent it you must mention, that you want to compare with a string, not a column value. You can make it using your engine rules (usually enclose string with "'"), but it isn't secure, I think you should use placeholders engine, that doctrine provides, for example