Switch between multiple database in PDO

后端 未结 5 871
陌清茗
陌清茗 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条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 02:33

    I know that I am a couple of months late but you should be able to switch between databases from within your query.

    examples:

    $sql = "SELECT * FROM dbname.tablename";
    
    $sql = "SELECT * FROM anotherdbname.anothertablename"
    

    So even if your original $pdo object was used 'blahblah' as the dbname, you should still be okay based on the select examples I provided.

提交回复
热议问题