Configure database parameters in ZendFramework
Configure database parameters in Zend Framework
- I created a 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 set up file paths and other information.
- The following describes how to configure mysql database information in a zend framework 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,
- On 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: setdefaadapter adapter ($ dbAdapter );
- Zend_Registry: set ('dbadapter ', $ dbAdapter );
-
|