简单显示数据库结果

编程入门 行业动态 更新时间:2024-10-28 16:22:26
本文介绍了简单显示数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-23 13:50:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1042357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!