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.