Reputation: 564
I'm looking to execute a raw SQL query in a Zend Controller.
I looked here http://framework.zend.com/manual/1.11/en/zend.db.statement.html and it says to do
$sql = 'SELECT * FROM bugs WHERE reported_by = ? AND bug_status = ?';
$stmt = new Zend_Db_Statement_Mysqli($db, $sql);
$stmt->execute(array('goofy', 'FIXED'));
but whenever I do that it gives me an error cause of the $db.... What's $db supposed to hold cause it doesn't say anywhere in the documentation...
Also whenever I'm done I would like to return an array with whatever the result was, what would I be able to do something like $resultArray = $stmt->execute(array('goofy', 'FIXED'));
???
Thanks,
Upvotes: 2
Views: 1653
Reputation: 2989
Try this code:
Put code in bootstrap.php
protected function _initRegistry() {
$this->bootstrap('db');
$dbc = $this->getResource('db');
$dbc->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Registry::set('db', $dbc);
global $db;
$db = Zend_Registry::get('db');
}
Upvotes: 0
Reputation: 562951
It should be an object of type Zend_Db_Adapter.
Elsewhere in the documentation examples, the variable $db
is commonly used as an instance of a Zend_Db_Adapter. I guess one is expected to read the full documentation, and notice conventions like that.
Re your comment:
You can load your application.ini file into a Zend_Config_Ini object, and then use that Zend_Config object as the argument to Zend_Db_Factory. See example here: http://framework.zend.com/manual/1.11/en/zend.db.adapter.html#zend.db.adapter.connecting.factory-config
Upvotes: 1