Reputation: 501
I have set up correctly the parameters for Zend_Db::factory and then I am querying like:
$select = $db->select()
->from('imdb')
->limit(10);
$stmt = $db->query($select);
$result = $stmt->fetchAll();
Question: Why I do not see anything displayed?
I continue and I am trying to display results by creating a new object
$moviesTBL = new Application_Model_DbTable_Imdb();
$this->view->albums = $moviesTBL->fetchAll();
If I combine it with a view it works fine BUT fetches all rows!!! How to make it fetch only first 10?
foreach($this->albums as $key=> $value)
{
echo $value ->rank.' '.$value->rating.' '.$value->title.' '.$value->year.' '.$value->number_of_votes.'<br>';
}
pana4219
Posts: 2
Joined: Mon Nov 04, 2013 6:45 pm
Upvotes: 0
Views: 131
Reputation: 5352
Try somthing like this:
$select = $db->select()
->from('imdb')
->limit(10);
$result = $db->fetchAll($select);
Other example:
$class = new Zend_Db_Table();
$db = $class->getDefaultAdapter();
$select = $db->select();
$select->from('imdb');
$select->limit(10);
$result = $db->fetchAll($select);
.ini
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root"
resources.db.params.dbname = ""
resources.db.params.charset = "utf8"
resources.db.isDefaultTableAdapter = true
Bootstrap.php:
protected function _initDb() {
Zend_Db_Table_Abstract::setDefaultAdapter($this->getPluginResource('db')->getDbAdapter());
}
Upvotes: 3