编辑:
$query->where('`value` = ?', $number); 看起来就可以了。我仍然不知道为什么它不能在正常条件下工作,但它是一种变通方法..仍在寻找正确的答案!
我正在尝试使用一个简单的查询数据库:
$number = 4;
$query = $this->select();
$query->where('value = ?', $number);
$row = $this->fetchRow($query);
但由于某种原因,我经常遇到这个错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'value = 4) LIMIT 1' at line 1
当我进行汇编以查看查询字符串时:
SELECT `mighty_table`.* FROM `mighty_table` WHERE (value = 4)
我的列名没有转义..
Zend DB 应该这样做吗? :|这很奇怪,因为我在其他项目中使用了相同的方法并且它总是有效..
最佳答案
Note: The values and identifiers in the SQL expression are not quoted for you. If you have values or identifiers that require quoting, you are responsible for doing this. Use the quote(), quoteInto(), and quoteIdentifier() methods of the database adapter.
例如,您可以使用 quoteInto :
$number = 4;
$query = $this->select();
$where = $this->getAdapter()->quoteInto('value = ?', $number);
$query->where($where);
$row = $this->fetchRow($query);
关于mysql - Zend DB where 子句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9705276/