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.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: \ PhP5 \ Ext"
OK, let's go ..
Index. php homepage, which is also the only entry
<? PHP
//... Omitted
$ Params = array ('host' => '2017. 0.0.1 ',
'Username' => 'root ',
'Password' => '123 ',
'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: dump ($ rows );
}
Function listbycategory (){
}
//... Omitted
}
?>
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 );
}
}
?>
AccessHttp: // 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"
}