If you have a website built using Zend that has a requirement for a blog section, you can install WordPress in a subfolder to manage the blog. The problem you now have is that you have to edit your database details in two separate locations, the .ini file for your Zend Application and the wp-config file of WordPress. Although this isn’t a big deal it can easily be forgotten leaving to potential issues in the future if some details were to change. This issue is most likely to occur when transferring the site from a local or test server with one set of database credentials to a live site with another set of database credentials.
Make WordPress use application.ini file of Zend to get Database details
The solution is to make WordPress use the Zend database configuration file to populate the database data in the wp-config file. This means that whenever you have a database credential to amend they only have to be amended in the one file. The code below shows how to achieve this.
If you do not already have a bootstrap.php file, create one. In the WordPress index.php file add
In the wp_config.php file, change the database definition lines (typically lines 16-28) to:
//get settings from application config file. $config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini', APPLICATION_ENV); $config = $config->resources->db->params; // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', $config->dbname); /** MySQL database username */ define('DB_USER', $config->username); /** MySQL database password */ define('DB_PASSWORD', $config->password);
WordPress will now use the database username and password set in your Zend application.ini file to connect to the database.