我正在尝试在“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";
但它返回:Unable to connect to your database server using the provided settings
.
这是我用来连接数据库的部分功能
$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;
}