本文介绍了简单显示数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我已经正确设置了 Zend_Db::factory 的参数,然后我查询如下:
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();
如果我将它与视图结合起来,它可以正常工作,但会获取所有行!!!如何让它只获取前 10 个?
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
推荐答案
尝试这样的事情:
$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);
.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:
Bootstrap.php:
protected function _initDb() {
Zend_Db_Table_Abstract::setDefaultAdapter($this->getPluginResource('db')->getDbAdapter());
}
这篇关于简单显示数据库结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论