数据库的简单显示结果

时间:2013-11-06 00:27:57

标签: zend-framework zend-db

我已正确设置Zend_Db :: factory的参数,然后我查询:

$select = $db->select()
->from('imdb')
->limit(10);

$stmt = $db->query($select);
$result = $stmt->fetchAll();

问题: 为什么我看不到任何东西?

我继续,我正在尝试通过创建新对象来显示结果

$moviesTBL = new Application_Model_DbTable_Imdb();
$this->view->albums = $moviesTBL->fetchAll();

如果我将它与视图结合使用它可以正常工作但是取出所有行!如何让它只获取前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

1 个答案:

答案 0 :(得分:3)

尝试这样的事情:

$select = $db->select()
->from('imdb')
->limit(10);

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

其他例子:

$class = new Zend_Db_Table();
$db = $class->getDefaultAdapter();
$select = $db->select();
$select->from('imdb');
$select->limit(10);

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

。在

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