[PHP] php 在Zend Framework中配置数据库参数 →→→→→进入此内容的聊天室

来自 , 2019-03-24, 写在 PHP, 查看 143 次.
URL http://www.code666.cn/view/92a08bf9
  1. 我是用zend studio 7.2.1建立的zend framework project
  2. 也就是说我的框架是由zend stduio7.2.1 帮我建立了文件路径等信息的
  3. 下面讲讲如何在建立好的zend framework project中配置mysql数据库信息
  4. 1
  5. 在application/configs的文件下建立一个config.ini文件
  6. 配置信息如下:
  7. [general]
  8. db.adapter=PDO_MYSQL
  9. db.config.host=localhost/IParess      
  10. db.config.username=username
  11. db.config.password=password
  12. db.config.dbname=databasename
  13.  
  14. 2
  15. 在pulibc 目录的index.php页面中
  16. /** Zend_Application */
  17. require_once 'Zend/Application.php';
  18. 的下面插入
  19. //set the datase config
  20. require_once 'Zend/Config/Ini.php';
  21. require_once 'Zend/Registry.php';
  22. require_once 'Zend/Db.php';
  23. require_once 'Zend/Db/Table.php';
  24. $config=new Zend_Config_Ini('./../application/configs/config.ini',null, true);
  25. Zend_Registry::set('config',$config);
  26. $dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
  27. $dbAdapter->query('SET NAMES UTF8');
  28. Zend_Db_Table::setDefaultAdapter($dbAdapter);
  29. Zend_Registry::set('dbAdapter',$dbAdapter);
  30. //该片段来自于http://yuncode.net
  31.  

回复 "php 在Zend Framework中配置数据库参数"

这儿你可以回复上面这条便签

captcha