How to insert data in two different tables of two different database in php

前端 未结 5 839
醉酒成梦
醉酒成梦 2021-01-21 09:35

I have to insert data in two different database\'s table. I have created database1 and table1 for database1, also i have created database2 and table2 for database2.

For

5条回答
  •  盖世英雄少女心
    2021-01-21 10:11

    first create two database connections

    $connect1 = mysql_connect("localhost","root",""); 
    $connect2 = mysql_connect("localhost","root",""); 
    

    Then select the database for each connection.

    mysql_select_db("database1",$connect1); // select database1 
    mysql_select_db("database2",$connect2); // select database2 
    

    Then pass in a second argument for mysql_query which is the respective connection for the query.

    mysql_query("SELECT ... ", $connect1);
    mysql_query("SELECT ... ", $connect2);
    

提交回复
热议问题