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.