Php 代码点火器:CI_DB_mysqli_驱动程序无法转换为字符串

Php 代码点火器:CI_DB_mysqli_驱动程序无法转换为字符串,php,codeigniter,mysqli,Php,Codeigniter,Mysqli,我有一个来自另一个数据库的现有用户数据库,希望在我的新站点上使用它,使用codeigniter和一个新数据库。这两个数据库都在mysql上运行,我像下面一样配置了my database.php,并配置了另一个数据库连接 $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => 'root',

我有一个来自另一个数据库的现有用户数据库,希望在我的新站点上使用它,使用codeigniter和一个新数据库。这两个数据库都在mysql上运行,我像下面一样配置了my database.php,并配置了另一个数据库连接

$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\u 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;
            }

          }
但是下面有一个错误,我是codeigniter的新手,不确定这是否是从另一个数据库查询的正确方法,任何建议都会有帮助!提前谢谢

类CI_DB_mysqli_驱动程序的对象无法转换为字符串

改变这个

$otherdb=$this->load->database('otherdb',TRUE);

$this->otherdb=$this->load->database('otherdb',TRUE);

它将工作。

将此$this->$otherdb更改为$otherdb->where和$otherdb->不使用“$this->”,因为您正在处理“otherdb”…

Compa,您在调用时出错

$result = $this->$otherdb->get('members');
错误在于
$this
-您必须执行以下操作:

$result = $otherdb->get('members');
祝你好运

PS:我也有类似的错误