Zend Framework connection MySQL DB instance analysis _php instance

Source: Internet
Author: User
Tags php website zend framework
This article describes the Zend Framework connection to the MySQL database method. Share to everyone for your reference, as follows:

Before you look at these, make sure that you have properly loaded the PDO extension. The practice is to edit the php.ini.
Manually add these two lines (preceded by a semicolon;):

Extension=php_pdo.dllextension=php_pdo_mysql.dll

And we're going to put Extension_dir

Refer to the directory where Php_pdo.dll and Php_pdo_mysql.dll are located, such as

Extension_dir = "C:/php5/ext"

Ok,let ' s go.

index.php website homepage, also the only entrance

<?php//... Omit $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

<?phpclass 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::d UMP ($rows);    }    function Listbycategory () {    }    //... Omit}?>

articlecontroller.php

Class Articlecontroller extends Zend_controller_action {  private $view;  Private $article;  function __c****truct () {    $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);  }? >

Visit Http://happycms/article/listall

Get the following output:

Array (1) {[0] = = Array (+) {  ["articleid"] = + string (1) "1"  ["categoryid"] = + string (1) "0"  ["Artic Letitle "] + string (4)" Test "  [" articlefromwhere "] = + string (3)" SDF "  [" articlekeywords "] + string (5 ) "Sdfds"  ["articledescription"] + string (4) "Test"  ["articlebody"] + string (9) "SFFSDFSDF"  [" AuthorName "] + string (8)" Haohappy "  [" Authoremail "] and" s ... @df. com "  [" issticky "] + = String (1) "0"  ["isrecommanded"] + = string (1) "0"  ["includeattachment"] = = string (1) "0"  [" Addtime "] = string (+)" 0000-00-00 00:00:00 "  [" lastedittime "] + = string (+ 0000-00-00 00:00:00"  [" Checktime "] + = string (19)" 0000-00-00 00:00:00 "}

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework framework.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.