The following article describes how to connect zend_db to MySQL (with complete code). Before reading these things, make sure that the PDO extension is loaded correctly. Our specific practice is to edit php. ini and manually Add the following two lines (there is no semicolon before;): extensionphp_pdo.dllextensionphp_pdo_MySQL (set up with PHP
The following article describes how to connect zend_db to MySQL (with complete code). Before reading these things, make sure that the PDO extension is loaded correctly. Our specific practice is to edit php. ini and manually Add the following two lines (there is no semicolon before;): extension = php_pdo.dll extension = php_pdo_MySQL (with PHP
The following article describes how to connect zend_db to MySQL (with complete code). Before reading these things, make sure that the PDO extension is loaded correctly. You can edit php. ini and manually Add the following two rows (there is no semicolon before ;):
Extension = php_pdo.dll
Extension = php_pdo_MySQL (the best combination with PHP). dll
Then, set extension_dir
Point to the directory of php_pdo.dll and php_pdo_MySQL (the best combination with PHP). dll, as shown in figure
- extension_dir = "C:\php5\ext"
Index. php homepage, which is also the only entry
The PHP code is as follows:
-
- //... Omitted
- $ Params = array ('host' => '2017. 0.0.1 ',
- 'Username' => 'root ',
- 'Password' => '123 ',
- 'Dbname' => 'happycms ');
- $ Db = Zend_Db: factory ('pdomysql (best combination with PHP) ', $ params );
- Zend: register ('db', $ db );
- ?>
- Lib/App/Article. php
Zend_db is connected to MySQL: the PHP code is as follows:
-
- 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"
- }
The above content is an introduction to connecting zend_db to MySQL (with the complete code). I hope you will get some benefits.