我遇到数据库连接问题。这是我得到的错误:
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
有任何想法吗?