dqqy64515 2018-10-12 10:49
浏览 61

如何在codeigniter中运行并发数据库连接正常mysqli和自定义pdo [重复]

This question already has an answer here:

Afternoon all. I have a strange question. I need to have two connections to our db in codeigniter instance. I need to have the standard ci method but i also need to create a pdo class instance for use in new feature setup. We are unfortunately in the position where we have to run a v1.0 system using the old db connectivity and a new v2.0 system using a pdo db object.

How can I go about creating a global instance of this pdo class so that it only gets instantiated once per process call to codeigniter.

</div>
  • 写回答

1条回答 默认 最新

  • doubiaokai4998 2018-10-12 10:57
    关注

    you should add another DB in application/config/database.php and change dbdriver and hostname like

    $db['pdodb']['hostname'] = "mysql:host=localhost'";
    $db['pdodb']['username'] = "root";
    $db['pdodb']['password'] = "";
    $db['pdodb']['database'] = "your_db";
    $db['pdodb']['dbdriver'] = "pdo";
    $db['pdodb']['dbprefix'] = "";
    $db['pdodb']['pconnect'] = TRUE;
    $db['pdodb']['db_debug'] = FALSE;
    $db['pdodb']['cache_on'] = FALSE;
    $db['pdodb']['cachedir'] = "";
    $db['pdodb']['char_set'] = "utf8";
    $db['pdodb']['dbcollat'] = "utf8_general_ci";
    $db['pdodb']['swap_pre'] = "";
    $db['pdodb']['autoinit'] = TRUE;
    $db['pdodb']['stricton'] = FALSE;
    

    and you can load database like this

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

    and finally you can execute query like this

    $query = $pdodb->select('col1, col2,col3')->get('your_table');
    

    for more information about multiple database

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题