문제

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.

도움이 되었습니까?

해결책

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

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

then

$link->select_db('database2');

다른 팁

SELECT * FROM database_2.table ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top