0
我有一个来自另一个数据库的现有用户数据库,并希望在我的新网站上使用codeigniter与一个新的数据库都运行在MySQL上,我配置我的database.php像下面,并配置另一个数据库连接。代码点火器:CI_DB_mysqli_driver无法转换为字符串
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'new_database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['otherdb'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'members_database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
现在我试图查询我的Users_model.php上的用户名和密码我的功能是这样的。
public function login($username, $password){
$otherdb = $this->load->database('otherdb', TRUE);
$this->$otherdb->where('user_name', $username);
$this->$otherdb->where('user_pass', $password);
$result = $this->$otherdb->get('members');
if($result->num_rows() == 1){
return $result->row(0)->ID;
}else{
return false;
}
}
,但得到以下错误,我新用笨,不知道这是从另一个数据库查询的方法得当,任何建议将帮助!提前致谢!
类CI_DB_mysqli_driver的对象不能被转换成字符串
那很简单,谢谢! – KaoriYui