0

我遇到数据库连接问题。这是我得到的错误:

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

有任何想法吗?

4

1 回答 1

0

呃,发现问题了。有人在另一个文件中手动添加了第二组数据库设置,并从那里调用它们。真是一团糟!

于 2012-06-19T18:42:29.810 回答