简体   繁体   中英

Connect to database remotely from another server

I need to connect a website A in a server A to a mysql database B in a server B (cpanel). I'm using this code for my connection:

$myServer = "host_B"; $myUsername = "user_database_B"; $myPassword = "pass_database_B"; $myDatabase = "name_database_B";

$con = mysqli_connect($myServer,$myUsername,$myPassword );

I'm getting this error: "Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.​"

I also have the port 3306 opened and in server BI have allowed the ip of the website A for remote connections to the database.

I'm just wondering if you can help me and give me ideas what the problem could be.

mysqli_connect takes four parameters. You forgot to include the database name $myDatabase

$con = mysqli_connect($myServer, $myUsername, $myPassword, $myDatabase);

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