views:

40

answers:

1

I have a cakePHP app with my DB servers configured in the app/config/ database.php file. However, I need to use the get_cfg_var ('mysql.default_host') to get the host name because the client does not want the name hardcoded. I would appreciate a quick response regarding where the changes need to be made. Thanks

+1  A: 

In the /app/config/bootstrap.php file, add a new constant like so:

<?php
// get the default host name set in php.ini
$defaultHost = get_cfv_var('mysql.default_host');
// might want it to try using localhost if get_cfv_var is not set
if(!$defaultHost) {
  $defaultHost = "localhost";
}
define("DB_HOST_NAME", $defaultHost);
?>

Then in /app/config/database.php, in the default array (or whatever DB array you are using for production) use the constant:

<?php
// set up the database connection
var $default = array(
     'driver' => 'mysql',
     'persistent' => false,
     'host' => DB_HOST_NAME, // use the default set by get_cfv_var()
     'login' => 'username',
     'password' => 'password',
     'database' => 'database',
     'prefix' => '',
    );
?>

Hope this helps!

spelley
Yes it did. Thanks Spelley.
Ashu