加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 具有多个数据库连接的Codeigniter查询分析器

发布时间:2020-12-13 17:18:59 所属栏目:PHP教程 来源:网络整理
导读:我正在使用codeigniter 2.0或特别是3.0-dev.问题是我有多个数据库连接,而探查器只显示来自默认连接$this- db的查询. class table_m extends CI_Model{ function __construct() { parent :: __construct(); $this-db2 = $this-load-database('production',TRU
我正在使用codeigniter 2.0或特别是3.0-dev.问题是我有多个数据库连接,而探查器只显示来自默认连接$this-> db的查询.

class table_m extends CI_Model
{

    function __construct()
    {
        parent :: __construct(); 
        $this->db2 = $this->load->database('production',TRUE);
    }

    function sel_pameran($ukmper=NULL)
    {
        $sql = "SELECT * from table1";

        $query = $this->db2->query($sql);
        return $query->result();
    }
}

此查询不会显示在探查器中,因为它使用$this-> db2.那么如何使分析器显示每个执行的查询,从哪个数据库无关紧要?

解决方法

看到这个问题.这是一个更简单的解决方案.
How can I display my database queries in the Codeigniter Profiler when I load my databases in my models?

只需将数据库存储到主CI类,分析器就可以访问它们.

function __construct()
{

    parent::__construct();

    $CI =& get_instance();
    if( is_null( $CI->Companies_db ) )
        $CI->Companies_db =& $this->load->database( 'companies',TRUE,TRUE );          

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读