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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ashu
  • 11
  • 1

1 Answers1

1

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
  • 561
  • 1
  • 4
  • 13