搜索
首页php教程PHP开发Zend Framework连接Mysql数据库实例分析

本文实例讲述了Zend Framework连接Mysql数据库的方法。分享给大家供大家参考,具体如下:

在看这些之前请确保你正确加载了PDO扩展。做法是编辑php.ini 。
手动增加这两行(前面要没有分号;):

extension=php_pdo.dll
extension=php_pdo_mysql.dll

   

然后要把extension_dir

指向php_pdo.dll及php_pdo_mysql.dll所在目录,如

extension_dir = "C:/php5/ext"

   

OK,let's go..

index.php 网站首页,也是唯一入口

<?php
//...省略
$params = array (&#39;host&#39;   => &#39;127.0.0.1&#39;,
         &#39;username&#39; => &#39;root&#39;,
         &#39;password&#39; => &#39;123456&#39;,
         &#39;dbname&#39;  => &#39;happycms&#39;);
$db = Zend_Db::factory(&#39;pdoMysql&#39;, $params);
Zend::register(&#39;db&#39;, $db);
?>

   

lib/App/Article.php

<?php
class App_Article {
    private $db;
    function App_Article() {
        $this->db = Zend::registry(&#39;db&#39;);
    }
    function listAll() {
        $result = $this->db->query(&#39;SELECT * FROM article&#39;);
        $rows = $result->fetchAll();
        Zend::dump($rows);
    }
    function listByCategory() {
    }
    //...省略
}
?>

   

ArticleController.php

class articleController extends Zend_Controller_Action {
  private $view;
  private $article;
  function __c****truct() {
    $this->view = Zend::registry(&#39;view&#39;);
    $this->article = new App_Article();
  }
  public function listAllAction() {
    $this->article->listAll();
    $this->view->title=&#39;View Articles&#39;;
    echo $this->view->render(TPL_DIR.&#39;/tplView.php&#39;);
  }
  function __call($action, $arguments)
  {
    $this->_redirect(&#39;./&#39;);
    print_r($action);
    print_r($arguments);
  }
}
?>

   

访问 http://happycms/article/listall

得到以下输出:

array(1) {
 [0] => array(15) {
  ["articleid"] => string(1) "1"
  ["categoryid"] => string(1) "0"
  ["articletitle"] => string(4) "test"
  ["articlefromwhere"] => string(3) "sdf"
  ["articlekeywords"] => string(5) "sdfds"
  ["articledescription"] => string(4) "test"
  ["articlebody"] => string(9) "sffsdfsdf"
  ["authorname"] => string(8) "haohappy"
  ["authoremail"] => string(11) "s...@df.com"
  ["issticky"] => string(1) "0"
  ["isrecommanded"] => string(1) "0"
  ["includeattachment"] => string(1) "0"
  ["addtime"] => string(19) "0000-00-00 00:00:00"
  ["lastedittime"] => string(19) "0000-00-00 00:00:00"
  ["checktime"] => string(19) "0000-00-00 00:00:00"
 }

   

希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。

更多Zend Framework连接Mysql数据库实例分析相关文章请关注PHP中文网!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器