Zend Framework connects to Mysql database instance analysis, zendmysql

Source: Internet
Author: User

Zend Framework connects to Mysql database instance analysis, zendmysql

This article describes how to connect Zend Framework to the Mysql database. We will share this with you for your reference. The details are as follows:

Before reading this, make sure that you have correctly loaded the PDO extension. Edit php. ini.
Manually add the two rows (no semicolon before ;):

extension=php_pdo.dllextension=php_pdo_mysql.dll

Then, set extension_dir

Point to the directory where php_pdo.dll and php_pdo_mysql.dll are located, as shown in figure

extension_dir = "C:/php5/ext"

OK, let's go ..

Index. php homepage, which is also the only entry

<? Php //... omit $ params = array ('host' => '2017. 0.0.1 ', 'username' => 'root', 'Password' => '000000', '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 :: dump ($ rows);} function listByCategory (){}//... omitted}?>

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

Access http: // happycms/article/listall

The following output is displayed:

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

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.