Zend Framework:使用 join 和 PDO 名称参数绑定进行选择

问题描述 投票:0回答:3

我正在使用 Zend Framework,并一直在尝试执行连接查询并使用命名参数绑定。参考以下两篇文章。当我刚刚加入时,一切正常。当我添加名称绑定时,它会收到此错误:

消息:SQLSTATE[HY093]:参数号无效:没有参数 绑定

如何在ZF表界面进行连接查询?

Zend Framework:如何通过指定列的值查找表行?

我已经缩小了它的规模,试图消除任何可能的错误,但它仍然出现错误,不知道为什么。

$query = "country = :cc";  // changing :cc to 'US' everything works
$params = array(':cc' => 'US');

$db = $this->getDbTable();
$select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

$select->setIntegrityCheck(false)
       ->join(array("daytable"), 'weektable.showid = daytable.id')
       ->where($query, $params);

$rowset = $db->fetchAll($select);
php mysql zend-framework pdo zend-db-table
3个回答
1
投票

试试这个:

->where('country = ?', 'US')

使用 Zend_Db_Select 绑定参数


1
投票
$query = "country = ?";  // changing :cc to 'US' everything works
$param = 'US';

$db = $this->getDbTable();
$select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

$select->setIntegrityCheck(false)
       ->join(array("daytable"), 'weektable.showid = daytable.id')
       ->where($query, $param);

$rowset = $db->fetchAll($select);

0
投票
$query = "country = :cc";  // changing :cc to 'US' everything works
$params = array('cc' => 'US');

$db = $this->getDbTable();
$select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);

$select->setIntegrityCheck(false)
       ->join(array("daytable"), 'weektable.showid = daytable.id')
       ->where($query);

$select->bind($params);

$rowset = $db->fetchAll($select);
© www.soinside.com 2019 - 2024. All rights reserved.