douruhu4282 2015-09-14 18:16
浏览 21
已采纳

使用PDO和MySQL的“训练模式”

I'm planning to do a "training mode" to my system. When it's activated, the systems database connection would get table users from the database 1 but tables customers and products from the database 2.

What would be the best way to do this? I have following database connection (using PDO).

$pdo = new PDO(DB_TYPE.':host='.DB_HOST.'; dbname='.DB_NAME, DB_USER, DB_PASS);

The system looks for training mode status from users and if it's true, it should connect another database's customers and products. Can I get some of the tables from one database and some of the other?

  • 写回答

2条回答 默认 最新

  • dongwen9947 2015-09-14 18:24
    关注

    Yes of course you can, all you need to do is create another PDO connection to the other database.

    // original connection
    $pdo = new PDO(DB_TYPE.':host='.DB_HOST.'; dbname='.DB_NAME, 
                   DB_USER, DB_PASS);
    
    // test mode connection
    $pdo_test = new PDO(DB_TYPE.':host='.DB_HOST.'; dbname='.DB_NAME_TEST, 
                   DB_USER_TEST, DB_PASS_TEST);
    

    Then its just a f.l.o.c to make sure you use the correct connection object in whichever query you are execution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计