forum share
   textsms      forum    

PDO use 2 database connections in one query

INDEX \ Articole/intrebari \ PDO use 2 database connections in one query

PDO use 2 database connections in one query

text_format+  text_format-


$db1 = new PDO('mysql:host='.$db_host1.';dbname='.$db_name1,$db_username1,$db_pass1);
$db2 = new PDO('mysql:host='.$db_host2.';dbname='.$db_name2,$db_username2,$db_pass2);

$db1->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
$db2->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);

$today = date("Y-m-d");
$stmt1 = $db1->query("SELECT * FROM events WHERE event_start >= $today ORDER BY event_start ASC");
$stmt2 = $db2->query("SELECT * FROM events WHERE event_start >= $today ORDER BY event_start ASC");

//this works for only one of the database. in this case $stmt1 which connects to db1
while($row = $stmt1->fetch()) {
//echo'd data will go here
}






update Ultima actualizare: 22/05/2021
done Informatiile cuprinse in aceasta sectiune sunt verificate si actualizate periodic.

list Articole recente
arrow_back Inapoi


© 2025 EVIDWEB. Toate drepturile rezervate. Design: EVIDWEB

share   forum   textsms