Home > Backend Development > PHP Tutorial > Zend Framework connects to Mysql database instance analysis, zendmysql_PHP tutorial

Zend Framework connects to Mysql database instance analysis, zendmysql_PHP tutorial

WBOY
Release: 2016-07-12 08:56:39
Original
840 people have browsed it

Zend Framework connects to Mysql database instance analysis, zendmysql

This article describes the method of Zend Framework connecting to Mysql database. Share it with everyone for your reference, the details are as follows:

Please make sure you have the PDO extension loaded correctly before looking at these. The way to do this is to edit php.ini.
Manually add these two lines (without semicolon;):

extension=php_pdo.dll
extension=php_pdo_mysql.dll

Copy after login

Then add extension_dir

points to the directory where php_pdo.dll and php_pdo_mysql.dll are located, such as

extension_dir = "C:/php5/ext"

Copy after login

OK, let's go..

index.php is the homepage of the website and the only entrance

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

Copy after login

lib/App/Article.php

<&#63;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() {
    }
    //...省略
}
&#63;>

Copy after login

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);
  }
}
&#63;>

Copy after login

Visit http://happycms/article/listall

Get the following output:

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"
 }

Copy after login

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

Articles you may be interested in:

  • Zend Framework implements the method of storing session in memcache
  • Detailed explanation of usage of Zend Framework paging class
  • Zend Framework Generate verification code and implement verification code verification function (with demo source code download)
  • Zend_Mail of Zend Framework implements verification function of sending email and solves the problem of garbled title
  • Zend_Form component of Zend Framework tutorial Methods to implement form submission and display error prompts
  • Zend Framework implementation of multi-file upload function example
  • Environment configuration for getting started with Zend Framework and the first Hello World example (with demo source code download)
  • Zend Framework Tutorial: How to connect to the database and perform add/delete queries (with demo source code download)
  • A summary of Zend Framework entry-level knowledge points
  • A simple example of Zend Framework Cache usage
  • Zend Framework basic page layout analysis
  • Detailed explanation of Zend Framework smarty usage examples
  • Zend Framework implements a guestbook with basic functions (with demo source code download)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111889.htmlTechArticleZend Framework connection Mysql database example analysis, zendmysql This example describes the method of Zend Framework connecting Mysql database. Share it with everyone for your reference, the details are as follows: Looking at this...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template