我遇到了数据库连接问题。 这是我得到的错误:
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
这是我的database.php文件设置:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user';
$db['default']['password'] = 'password';
$db['default']['database'] = 'dvp';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
我已将此代码放在database.php文件的底部:
echo '<pre>';
print_r($db['default']);
echo '</pre>';
echo 'Trying to connect to database: ' .$db['default']['database'];
$dbh=mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password'])
or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['default']['database']);
echo '<br /> Connected OK:' ;
die( 'file: ' .__FILE__ . '--> Line: ' .__LINE__);
以下信息显示:
Array
(
[hostname] => localhost
[username] => user
[password] => password
[database] => dvp
[dbdriver] => mysql
[dbprefix] =>
[pconnect] => 1
[db_debug] => 1
[cache_on] =>
[cachedir] =>
[char_set] => utf8
[dbcollat] => utf8_general_ci
[swap_pre] =>
[autoinit] => 1
[stricton] =>
)
Trying to connect to database: dvp
Connected OK
有什么想法吗?
答案 0 :(得分:0)
Ug,发现了这个问题。有人在另一个文件中手动添加了第二组数据库设置,并从那里调用它们。真糟糕!