Before reading this, make sure that you have correctly loaded the PDO extension.
Edit php. ini
Manually Add the following two rows (there must be no semicolon before ;):
Extension = php_pdo.dll
Extension = 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: php5ext"
OK, lets go ..
Index. php homepage, which is also the only entry
The PHP code is as follows:
<? Php
//... Omitted
$ Params = array (host => 127.0.0.1,
Username => root,
Password = & gt; 123456,
Dbname => happycms );
$ Db = Zend_Db: factory (pdoMysql, $ params );
Zend: register (db, $ db );
?>
Lib/App/Article. php
The PHP code is as follows:
<? 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 (){
}
//... Omitted
}
?>
The PHP code is as follows:
ArticleController. php
Class articleController extends Zend_Controller_Action {
Private $ view;
Private $ article;
Function _ construct (){
$ 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"
}