TapeGun007 Posted February 16, 2017 Share Posted February 16, 2017 I have mySQLi statement that looks similar to this: $sql = "SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; $stmt = $consd->prepare($sql); $stmt->bind_param('sss', $Search,$Search, $Search); Works fine. But what I cannot seem to find is what if I had two databases with all the same tables and I want to query both of them using mySQLi? I've tried all types of things, but I *think* because it's older mysql code that I'm not getting the syntax quite right... Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 16, 2017 Share Posted February 16, 2017 Do you mean query them together? Or do separate queries on each? Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 16, 2017 Solution Share Posted February 16, 2017 Prefix the table name with the database name $sql = "SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM database1.table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) UNION SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM database2.table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; Databases must be on the same server. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 16, 2017 Share Posted February 16, 2017 if I had two databases with all the same tables Why on earth would you have that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.