HubsInfo Network
You're browsing our forum as a Guest meaning you can only see a portion of the forum in read-only mode. To view all forum nodes and be able to create threads/posts please register or log-in.
PHP MySQL Linux Material Design Web Hosting Online Games SimCity BuildIt

PDO use 2 database connections in one query

0 Members and 1 Guest are viewing this topic.

hubsinfo

PDO use 2 database connections in one query
« on: September 25, 2016, 12:40:51 AM »
Code: [Select]
$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
}






--
Ref: http://stackoverflow.com/questions/17434921/pdo-use-2-database-connections-in-one-query
 



Linux Ubuntu Guides Linux games - Lutris.net