1

I am using Zend Framework and have been trying to do a joined query and also use named param binding. Referencing from the two posts below. When I just do the join everything works. When I add the name binding then it gets this error:

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?

I have scaled it way down trying to remove any possible errors but it is still getting the error and no idea why.

$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);
Community
  • 1
  • 1
Brandon
  • 320
  • 1
  • 4
  • 13

2 Answers2

1

Try this:

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

Binding params with Zend_Db_Select

Mike B
  • 31,886
  • 13
  • 87
  • 111
  • Yes this does work and I tried that but forgot to add it to my question. How come something like this doesn't ->where("day.dt BETWEEN ? AND ?", array($today, $tomorrow)); //'2011-09-25 02:00:00' AND '2011-09-26 18:00:00 but when I add the strings into the where it works just fine. – Brandon Sep 26 '11 at 03:16
  • The other question is why does using the ':variable' method not work? – Brandon Sep 26 '11 at 03:19
  • @Brandon http://framework.zend.com/issues/browse/ZF-2211 - Unresolved, they suggest pairing up where clauses. I don't know enough about the internals of Zend_Db_Select to give you an absolute answer but I have a hunch it's because Zend_Db doesn't always use a PDO adapter. http://framework.zend.com/manual/en/zend.db.adapter.html – Mike B Sep 26 '11 at 04:17
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);
Mr Coder
  • 8,169
  • 5
  • 45
  • 74