Zend Framework Connection MySQL database instance analysis _php instance

Source: Internet
Author: User
Tags php website zend zend framework

The example of this article describes the Zend Framework connection to the MySQL database method. Share to everyone for your reference, specific as follows:

Before you look at these, make sure you load the PDO extension correctly. The procedure is to edit php.ini.
Manually increase the two lines (preceded by no semicolon;):

Extension=php_pdo.dll
Extension=php_pdo_mysql.dll

And then I'm going to put Extension_dir

Point 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, is 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

<?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::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"
  [" 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 "s ... @df. com"
  ["Issticky"] => string (1) "0"
  ["isrecommanded"] => String (1) "0"
  ["IncludeAttachment"] => string (1) "0"
  ["Addtime"] => string (19) "0000-00-00 00:00:00" c15/>["Lastedittime"] => string (a) "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 site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the Zend 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.