Configure database parameters in Zend Framework
- I created the zend framework project using zend studio 7.2.1
- That is to say, my framework was created by zend stduio7.2.1 to help me create the file path and other information
- The following will talk about how to create a good zend framework Configure the mysql database information in the project
- 1.
- 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
- //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);
-
-
Copy code
|