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.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog