mysql - Zend DB where 子句错误

标签 mysql zend-framework zend-db

编辑:

$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 应该这样做吗? :|这很奇怪,因为我在其他项目中使用了相同的方法并且它总是有效..

最佳答案

From zend manual :

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/

相关文章:

php - Zend Framework、pdo_mysql 和内存限制问题 - 为什么?

java - 如何使用连接池

php - 如何修复 phpMyAdmin 中的脚本超时错误?

php - MySQL 计算列滞后返回

REST API 包括/过滤附加字段/资源/集合

zend-framework - Zend 仅执行两个表更新之一

php - 将 Zend_Db 与 ORM 类混合

mysql - 构建 MySQL 查询背后的逻辑

php - 如何在 Zend Framework 中存储 cron 作业的脚本?

mysql - 连接两个数据库表 zend framework 1.12