我有一个 cakePHP 应用程序,在 app/config/database.php 文件中配置了我的数据库服务器。但是,我需要使用 get_cfg_var ('mysql.default_host') 来获取主机名,因为客户端不希望名称硬编码。
问问题
245 次
1 回答
1
在 /app/config/bootstrap.php 文件中,添加一个新常量,如下所示:
<?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);
?>
然后在 /app/config/database.php 中,在默认数组(或您用于生产的任何数据库数组)中使用常量:
<?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' => '',
);
?>
希望这可以帮助!
于 2009-12-26T23:26:19.893 回答