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

前端 未结 5 840
醉酒成梦
醉酒成梦 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 09:57

    Try the following code:

    $connect1 = mysql_connect("localhost","root","");
    mysql_select_db("database1", $connect1);
    $res1 = mysql_query("query",$connect1);
    
    $connect2 = mysql_connect("localhost","root","",true);
    mysql_select_db("database2", $connect2);
    $res2 = mysql_query("query",$connect2);  
    

    Note: So mysql_connect has another optional boolean parameter which indicates whether a link will be created or not. as we connect to the $connect2 with this optional parameter set to 'true', so both link will remain live.

提交回复
热议问题