简体   繁体   中英

How to connect to a mysql server with multihost?

In PHP, How to connect to a mysql server with multihost ?

In this picture, it's just an exemple my host in my server is "Database_Server_2" not "Database Server 2" and i have a port "81"

在此处输入图片说明

I try this code, but i don't work :/

 $link = mysql_connect('localhost:81/Database_Server_2', 'db_user', '******');

you can not connect multiple host in one connection, you have to use resource identifier($link) to manage connection like:

$link1 = mysql_connect('localhost:81/Database_Server_2', 'db_user', '******');
$link2 = mysql_connect('localhost:81/Database_Server_2', 'db_user', '******');

also mysql_connect will be deprecate very soon, use mysqli or PDO, they also better in performance.

MySQL does not support such named instances. The name "Database Server 2" is most probably only a name given to it in the phpMyAdmin config file, so you don't have to bother with remembering which IP/Port is which.

Look in the config file of phpMyAdmin, the second instance will be using a different port than the first instance. Just providing the port should work.

$link = mysql_connect('localhost:81', 'db_user', '******');

And the usual note: mysql_ functions are deprecated and will be removed from PHP in future versions. You should not write new code using them, use mysqli_* or PDO instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM