zendframework项目环境搭建后,看了下zend framework配置操作数据库,php教程如下:
在application/configs的文件下建立一个config.ini文件
配置信息如下:
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost/IParess
db.config.username=username
db.config.password=password
db.config.dbname=databasename
2、
在pulibc 目录的index.php页面中
/** Zend_Application */
require_once 'Zend/Application.php';
的下面插入
//set the datase config
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Table.php';
$config=new Zend_Config_Ini('./../application/configs/config.ini',null, true);
Zend_Registry::set('config',$config);
$dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
$dbAdapter->query('SET NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter',$dbAdapter);
就此,我就用我的本地wordpress数据库来测试下,就用wp_posts表来测试吧:
首先模型models建立Wp_posts.php