gpt4 book ai didi

php - 无法连接到数据库服务器

转载 作者:行者123 更新时间:2023-11-30 01:13:43 25 4
gpt4 key购买 nike

我正在尝试在“checkusername”之前连接到数据库。

database.php 在文件夹配置中:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'bmc';
//$db['default']['database'] = 'bmc_void';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = 'application/cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = "3306";

但它返回:无法使用提供的设置连接到数据库服务器

这是我用来连接数据库的函数部分

$querysql = "SELECT * 
FROM `bmc_admin_login`
WHERE `admin_name` = '" . $user_name . "' ";

$db=$this->load->database();
//echo "querysql:".$querysql."<br>";
$query = $this->db->query ( $querysql );
$user = $query->row ();
//echo count($user);
if (! isset ( $user ) || ! is_object ( $user ) || count ( $user ) == 0) {
$this->form_validation->_error_array ['admin_pass_error'] = '您填写的帐号不存在';
return false;
}
if ($user->admin_pass != $password) {
$this->form_validation->_error_array ['admin_pass_error'] = '请输入正确的密码';
return false;
}

最佳答案

您使用什么版本的 CI?我正在使用 2.3,我有这个配置并且它可以工作。并且您的 db_debug 等于 FALSE 尝试此配置。希望对您有所帮助。

 $active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'bmc';
$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;

关于php - 无法连接到数据库服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19262387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com