dtu36380 2017-06-21 01:17
浏览 90
已采纳

代码点火器:CI_DB_mysqli_driver无法转换为字符串

I have a existing users database from another database and want to use it on my new site using codeigniter with a new database both is running on mysql, i configured my database.php like below, and configure another database connection.

$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
);

Now i am trying to query the username and password on my Users_model.php my function is like this.

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;
            }

          }

But got a error below, i am new with codeigniter and not sure if this is the proper way of querying from another database, any advice would help! thanks in advance!

Object of class CI_DB_mysqli_driver could not be converted to string

  • 写回答

1条回答 默认 最新

  • doutang1992 2017-06-21 02:46
    关注

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

    It will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效