0

i'am using MySQLi to connect and fetch data from my MySQL server with
$link = new mysqli("localhost", "root", "","database_1");
I have a file that used for connection and data collection (dboperations.php) from above database
Now , i need to connect another database (e.g. database_2) and fetch data in the same php file.

Conditions:
Are databases on the same server? YES
Am i authorized to connect with same username and pass? YES

Is there any way to do that? Thanks.

Alper
  • 1,085
  • 3
  • 20
  • 39
  • There are 10 kinds of people: ones who google and ones who ask strangers to google for them – Your Common Sense Jun 20 '13 at 14:23
  • i am one kind of the people who searchs internet but cannot get the proper way of do it. Maybee i missed correct one but i think this site for asking the programming questions and getting answers. Even maybee one of people will see this thread and find correct answer from there ;) – Alper Jun 20 '13 at 14:28

2 Answers2

4

Use mysqli::select_db to switch databases on the same server:

$link = new mysqli('localhost', 'root', '', 'database1');

then

$link->select_db('database2');
JWMarchant
  • 356
  • 2
  • 8
0
SELECT * FROM database_2.table ...
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345