这是我目前的场景
1.我正在使用Cpanel进行实时共享主机。
2.当我尝试使用以下配置连接到数据库时
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user_dbuser';
$db['default']['password'] = 'password';
$db['default']['database'] = 'user_dbname';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['port'] = '3306';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$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'] = FALSE;
$db['default']['stricton'] = FALSE;
它给出了如下错误信息:
An Error Was Encountered
Your application/config/database.php file does not appear to contain a valid configuration array.
因此,为了找到错误,我将以下代码放在config / database.php的末尾附近。
$OK = mysql_select_db ($db['default']['database']);
if ($OK) //
{
// Nothing required, everything OK
// fred($db['default'], 'Database setting --> $db["default"]');
}else{
echo '<h1>Something terrible has happened</h1>';
echo '<pre>';
echo $db['default'];
echo '</pre>';
die;
}
这给出了以下输出。
A PHP Error was encountered
Severity: Warning
Message: mysql_select_db(): Access denied for user 'taxac'@'localhost' (using password: NO)
Filename: config/database.php
Line Number: 69
A PHP Error was encountered
Severity: Warning
Message: mysql_select_db(): A link to the server could not be established
Filename: config/database.php
Line Number: 69
Something terrible has happened
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: config/database.php
Line Number: 77
Array
我请您注意上述错误中的行
“用户'taxac'@'localhost'拒绝访问(使用密码:否)”
为什么不使用密码以及如何使用“密码”。
为了验证凭据,我尝试使用以下脚本连接到mysql
// TRY TO LOGIN WITH SIMPLE PHP NATIVE SCRIPT
$link = mysql_connect
(
$db['default']['hostname'],
$db['default']['username'],
$db['default']['password']
);
if (!$link) {
die('Not connected : ' . mysql_error());
}
else echo "MySQL connected";
// check the current db
$db_selected = mysql_select_db($db['default']['database'], $link);
if (!$db_selected) {
die ('Can\'t use <b>' .$db['default']['database'] .'</b> : ' . mysql_error());
}
else die('database is selected');
并成功完成以下输出
MySQL Connected.
database is selected
所以我确信
1。我提供的DB凭证是正确的**
** 2。我选择了正确的sql扩展名
** 3。错误与以上第四个输出中的跟随错误行有关[**
“访问被拒绝用户'taxac'@'localhost'(使用密码:否)”
因此,请帮助如何使用密码连接到数据库。
答案 0 :(得分:0)
尝试发表评论
$db['default']['port'] = '3306';
如果不起作用,请检查整理和字符设置。