zend_db正确连接MySQL数据库的实际操作方案

数据库 MySQL
我们今天主要向大家讲述的是zend_db正确连接MySQL数据库的正确解决方案,以下就是文章的主要内容描述,望你会有所收获。

以下的文章主要描述的是在实际操作中zend_db正确连接MySQL数据库的正确解决方案,假如你在实际操作中遇到相似的情况,但是你却不知道对其如何正确的解决,那么以下的文章对你而言一定是良师益友。

在看这些之前请确保你正确加载了PDO扩展。

作法是编辑php.ini

手动增加下面这两行(前面要没有分号;)

  1. extension=php_pdo.dll  
  2. extension=php_pdo_MySQL(和PHP搭配之最佳组合).dll 

然后要把extension_dir

指向php_pdo.dll及php_pdo_MySQL(和PHP搭配之最佳组合).dll所在目录,如

  1. extension_dir = "C:\php5\ext" 
  2. OK,let's go..  

 

index.php 网站首页,也是唯一入口

PHP代码如下:

<?php

省略

 

  1. $params = array ('host' => '127.0.0.1',  
  2. 'username' => 'root',  
  3. 'password' => '123456',  
  4. 'dbname' => 'happycms');  
  5. $db = Zend_Db::factory('pdoMySQL(和PHP搭配之最佳组合)', $params);  
  6. Zend::register('db', $db);  
  7. ?>   
  8. lib/App/Article.php  

 

PHP代码如下:

 

  1. <?php 
  2. class App_Article {  
  3. private $db;  
  4. function App_Article() {  
  5. $this->db = Zend::registry('db');  
  6. }  
  7. function listAll() {  
  8. $result = $this->db->query('SELECT * FROM article');  
  9. $rows = $result->fetchAll();  
  10. Zend::dump($rows);  
  11. }  
  12. function listByCategory() {  
  13. }  

 

省略

  1. }  
  2. ?>   

 

zend_db连接MySQL(附完整代码)的实际操作中我们要用到PHP代码如下:

 

  1. ArticleController.php  
  2. class articleController extends Zend_Controller_Action {  
  3. private $view;  
  4. private $article;  
  5. function __construct() {   
  6. $this->view = Zend::registry('view');  
  7. $this->article = new App_Article();   
  8. }   
  9. public function listAllAction() {  
  10. $this->article->listAll();  
  11. $this->view->title='View Articles';   
  12. echo $this->view->render(TPL_DIR.'/tplView.php');  
  13. }  
  14. function __call($action, $arguments)  
  15. {   
  16. $this->_redirect('./');  
  17. print_r($action);  
  18. print_r($arguments);  
  19. }  
  20. }  
  21. ?>   

 

访问 http://happycms/article/listall

得到以下输出:

 

  1. array(1) {  
  2. [0] => array(15) {  
  3. ["articleid"] => string(1) "1"  
  4. ["categoryid"] => string(1) "0"  
  5. ["articletitle"] => string(4) "test\"  
  6. ["articlefromwhere"] => string(3) "sdf"  
  7. ["articlekeywords"] => string(5) "sdfds"  
  8. ["articledescription"] => string(4) "test"  
  9. ["articlebody"] => string(9) "sffsdfsdf"  
  10. ["authorname"] => string(8) "haohappy"  
  11. ["authoremail"] => string(11) "s...@df.com"  
  12. ["issticky"] => string(1) "0"  
  13. ["isrecommanded"] => string(1) "0"  
  14. ["includeattachment"] => string(1) "0"  
  15. ["addtime"] => string(19) "0000-00-00 00:00:00"  
  16. ["lastedittime"] => string(19) "0000-00-00 00:00:00"  
  17. ["checktime"] => string(19) "0000-00-00 00:00:00"  

 

以上的相关内容就是对zend_db连接MySQL(附完整代码)的介绍,望你能有所收获。

【编辑推荐】

  1. MySQL AUTO_INCREMENT的正确用法
  2. MySQL数据库在linux下远程的连接错误
  3. MySQL分页查询通用存储过程的代码总结
  4. MySQL数据库中MySQL_real_connect的基本设置
  5. 在Windows环境下的MySQL数据库,精彩比赛
责任编辑:佚名 来源: 博客园
相关推荐

2010-05-27 10:17:24

连接MySQL

2010-06-02 13:58:30

MySQL数据库性能

2010-05-31 16:17:56

MySQL数据库性能

2010-03-26 09:06:06

Python连接数据库

2010-03-18 15:31:20

Python创建mys

2010-06-01 13:58:24

远程连接MySQL

2010-08-02 09:10:45

JDBC连接DB2

2010-05-28 10:34:39

连接MySQL数据库

2010-05-17 10:11:11

导入Mysql

2010-05-20 17:56:43

2010-05-19 15:12:32

导入MySQL

2010-05-27 14:55:40

简单备份MySQL

2010-06-12 09:53:19

2010-05-19 16:31:38

MySQL数据库

2010-07-30 15:44:04

DB2数据库

2010-07-30 14:21:10

DB2数据集

2010-05-31 17:55:46

MySQL导出 XLS

2010-05-20 10:10:30

MySQL数据库同步

2010-05-28 13:48:07

MySQL数据库密码

2010-06-01 10:17:01

重启MySQL数据库
点赞
收藏

51CTO技术栈公众号