列名称中的Zend TableGateway#(磅号或数字符号)

时间:2013-07-15 19:20:03

标签: zend-framework2 zend-db zend-db-table

我是Zend Framework 2的新手,我正在尝试将我的表连接到TableGateway并进行基本选择,应该是这样的:

SELECT * FROM <tableName> WHERE QMQT# = 1

在我的桌面模型中看起来像这样:

$rowset = $this->tableGateway->select(array('QMQT#' => $id));

问题似乎是查询中的#符号,因为我收到错误:

SQLSTATE[42S22]: Column not found: 0 [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0206 - Column "QMQT""#" not in specified tables. (SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)

我可以在普通的PDO中准备和执行此查询,但是通过Zend的TableGateway运行它会让我犯这个错误。 Zend中的表名中是否不允许使用井号/数字符号?有没有办法绕过这种过度逃避?

感谢您提出任何建议......

修改

我还尝试过quoteIdentifier()函数来解决这个问题:

$rowset = $this->tableGateway->select(array($this->tableGateway->getAdapter()->getPlatform()->quoteIdentifier('QMQT#') => $id));

但它所做的就是给我这个错误:

SQLSTATE[42000]: Syntax error or access violation: 0 [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0104 - Token QMQT was not valid. Valid tokens: < > = <> <= !< !> != >= �< �> �= IN NOT. (SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用表达式?

$rowset = $this->tableGateway->select(array(
    new Zend\Db\Sql\Expression\Expression('QMQT# as bob')
));
相关问题