Home >Backend Development >PHP Tutorial >zend framework configuration operation database instance analysis_PHP tutorial
After setting up the zendframework project environment, I took a look at the zend framework configuration and operation database. The PHP tutorial is as follows:
Create a config.ini file under the application/configs file
The configuration information is as follows :
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost/IParess
db.config.username=username
db.config.password=password
db.config.dbname=databasename
2,
In the index.php page of the pulibc directory
/**Zend_Application*/
require_once 'Zend/Application.php';
Insert below
//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 ; Code
The code is as follows:
true