Switch between multiple database in PDO

后端 未结 5 866
陌清茗
陌清茗 2020-12-10 01:48

I\'m new to PDO. I would like to know if there is anything similar to mysql_select_db in PDO, so that i can switch between different databases during runtime without the nee

5条回答
  •  -上瘾入骨i
    2020-12-10 02:46

    You actually do not need to specify the database upon connection at all. As long as you specify the database in every query, as Laz stated, this will work:

    $dbh = new PDO('mysql:host=127.0.0.1','USER','PASS');
    
    $query = "SELECT * FROM database1.table1";
    $query = "SELECT * FROM database2.table1";
    

提交回复
热议问题