473,378 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SELECT data from 2 databases

Hello,

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
  1. SELECT * FROM 
  2. (SELECT * FROM DB1.PmtsTbl where DB1.PmtsTbl.Date=x
  3. UNION
  4. SELECT * FROM DB2.PmtsTbl where DB2.PmtsTbl.Date=x)
  5. RESULTS ORDER BY Date
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);
  2.  
  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
0 1595

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

Similar topics

5
by: Han Lim | last post by:
Dear All, I have an application written by VB.Net with connect to a Microsoft Access database. One of the forms is to select data using oleAdapter and fill it into a dataset. In the oleAdapter, i...
2
by: nikou_70 | last post by:
Hi guys, I write a program with asp that select data from data base and show data in text box in asp, I want to know how user can change data and save it in this page, (I want to view and save data...
10
by: bsn | last post by:
Hello NG I want to select data from another DB, and use this data in currentDB. I have this SQL in a VBA procedure: Sql = "SELECT * FROM Firma " It is not working Any suggestions... ...
0
by: Lisa Coal | last post by:
I am using the Insert database command several times in a visual basic macro. Every time I use the command in the macro the Select Data Source screen appears even though the source is set in the...
11
by: cooperkuo | last post by:
Dear all, I have a question about ADO in the subform. I know how to use ADO to insert/update/select data into the sigin form, but wehn I try to do it in the form with subform((Datasheet). I don't...
1
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a DataSet with 2 tables. Now I want to select data like a INNER JOIN from these tables. In SQL Syntax I would write: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.f1 =...
5
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a DataSet with 2 tables. Now I want to select data like a INNER JOIN from these tables. In SQL Syntax I would write: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.f1 =...
1
by: sajjad525 | last post by:
php-mysql, how we can select data from multiple table please any one help me about the query which will be used to select data from mutiple table suppose if i have 3 table name like t1,t2,t3...
2
by: syoung69 | last post by:
Im fairly new to programming and am all self taught but i have managed to get the basics. My biggest problem is the select data line. Below i am trying to pull stats from a db showing only the...
0
by: sashiksu | last post by:
I'm trying to select data between tow dates(values given by date time pickers) I try more. but can't go forward. here is my code : Try If (con.State = ConnectionState.Closed) Then ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.