Home php教程 PHP开发 Analysis of Zend Framework connecting to Mysql database instance

Analysis of Zend Framework connecting to Mysql database instance

Dec 26, 2016 pm 03:56 PM

The example in 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 loaded the PDO extension correctly before reading these. The way to do this is to edit php.ini.
Add these two lines manually (without semicolon;):

extension=php_pdo.dll
extension=php_pdo_mysql.dll
Copy after login

Then point extension_dir

to php_pdo.dll And the directory where php_pdo_mysql.dll is located, such as

extension_dir = "C:/php5/ext"
Copy after login

OK,let's go..

index.php The homepage of the website is also the only entrance

<?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);
?>
Copy after login

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() {
    }
    //...省略
}
?>
Copy after login

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);
  }
}
?>
Copy after login

Visit http://happycms/article/listall

and 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

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

For more articles related to Zend Framework connection to Mysql database instance analysis, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)