By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

SELECT data from 2 databases

P: 72

I hope someone can help me!

I have 'payment' data in two databases. One db contains old/archived data. Each db contains the exact same table "PmtsTbl" but obviously the data is different.

I want to select all payment data from both db within a date range. I have the following sql which works in "Mysql Workbench"

Expand|Select|Wrap|Line Numbers
  2. (SELECT * FROM DB1.PmtsTbl where DB1.PmtsTbl.Date=x
  3. UNION
  4. SELECT * FROM DB2.PmtsTbl where DB2.PmtsTbl.Date=x)
Using PDO PHP I don't know how to combine the single SQL statement above with two PDO connection objects as show below.

Expand|Select|Wrap|Line Numbers
  1. $this->pdo = new PDO ("mysql:host=".DB_HOST.";dbname=".DB_1."; charset=utf8", DB_USER, DB_PASSWORD);
  3. $this->pdo = new PDO ("mysql:host=".DB_HOST.";dbname=".DB_2.";charset=utf8", DB_USER, DB_PASSWORD);
How do I use PHP code like
$this->stmt = pdo->prepare($sql)

Thank you in advance
Dec 30 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.