2011-09-26 77 views
1

我使用Zend框架,並試圖做一個加入的查詢,也使用命名參數綁定。參考下面的兩篇文章。當我剛剛完成加入時,一切正常。當我添加的名稱,然後結合它得到這個錯誤:Zend框架:選擇加入和PDO名稱參數綁定

Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

How to do a joined query in the ZF tables interface?

Zend Framework: How to find a table row by the value of a specified column?

我攀登它一路下滑試圖消除任何可能的錯誤,但它仍然得到錯誤,不想法爲什麼。

$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); 

回答

1

試試這個:

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

Binding params with Zend_Db_Select

+0

是這樣做的工作,我試過,但是忘記將它添加到我的問題。怎麼會有這樣的事情 - > where(「day.dt BETWEEN?AND?」,array($ today,$ tomorrow)); //'2011-09-25 02:00:00'AND'2011-09-26 18:00:00但是當我將字符串添加到它的工作方式就好了。 – Brandon

+0

另一個問題是爲什麼使用':variable'方法不起作用? – Brandon

+0

@Brandon http://framework.zend.com/issues/browse/ZF-2211 - 未解決,他們建議配對where子句。我對Zend_Db_Select的內部知識不夠了解,因爲Zend_Db並不總是使用PDO適配器。 http://framework.zend.com/manual/en/zend.db.adapter.html –

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);