0
votes

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.

2
There are 10 kinds of people: ones who google and ones who ask strangers to google for them - Your Common Sense
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

2 Answers

4
votes

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

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

then

$link->select_db('database2');
0
votes
SELECT * FROM database_2.table ...