国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

zend_db連接mysql(附完整代碼)

2019-11-18 16:31:47
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在看這些之前請(qǐng)確保你正確加載了PDO擴(kuò)展。

作法是編輯php.ini
手動(dòng)增加下面這兩行(前面要沒(méi)有分號(hào);):
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 網(wǎng)站首頁(yè),也是唯一入口

 

PHP代碼如下:

<?php
//...省略

$params = array ('host'     => '127.0.0.1',
                 'username' => 'root',
                 'passWord' => '123456',
                 'dbname'   => 'happycms');

$db = Zend_Db::factory('pdoMysql', $params);
Zend::register('db', $db);
?>


lib/App/Article.php

 

PHP代碼如下:

<?php
class App_Article {
        PRivate $db;
        function App_Article() {
                $this->db = Zend::registry('db');
        }

        function listAll() {
                $result = $this->db->query('SELECT * FROM article');
                $rows = $result->fetchAll();

                Zend::dump($rows);
        }

        function listByCategory() {
        }

        //...省略
}

?>

 


PHP代碼如下:

ArticleController.php
class articleController extends Zend_Controller_Action  {
    private $view;
    private $article;

    function __construct() {              
        $this->view = Zend::registry('view');
        $this->article = new App_Article();      
    }

    public function listAllAction() {
        $this->article->listAll();
        $this->view->title='View Articles';         
        echo $this->view->render(TPL_DIR.'/tplView.php');
    }

    function __call($action, $arguments)
    {      
        $this->_redirect('./');
        print_r($action);
        print_r($arguments);
    }
}
?>


訪(fǎng)問(wèn) 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"
    ["articledescr    ["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"
  }


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蕉岭县| 北辰区| 旺苍县| 永靖县| 合川市| 定安县| 涞源县| 金秀| 小金县| 浪卡子县| 八宿县| 固安县| 吉首市| 天津市| 东海县| 惠安县| 田东县| 舟山市| 息烽县| 凤山县| 石渠县| 建瓯市| 卢龙县| 黄平县| 巴马| 大港区| 蛟河市| 高青县| 黄陵县| 邯郸市| 陇川县| 武胜县| 福贡县| 安福县| 洛阳市| 苏尼特右旗| 温州市| 旬阳县| 前郭尔| 鄂托克前旗| 民勤县|