简体   繁体   中英

PHP Connect to MySQL Database in Other Server

I have 2 shared hostings: 1.1.1.1 and 2.2.2.2
I have a PHP script in 1.1.1.1 that connect to a database in 2.2.2.2
In Remote Database Access Hosts (2.2.2.2) I put '%' means that I allow connection from any IP
Database username in 2.2.2.2: foo
Database password in 2.2.2.2: bar

My PHP script:

mysql_connect('2.2.2.2:3306', 'foo', 'bar', true);

I got this error:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '2.2.2.2' (4)

If Your servers connected, make sure that on server 2.2.2.2 "my.cnf" mysql configuration file allows remote connections. This might help you.

Thanks for your help. It's about firewall, I contact my hosting and they fixed it for me.

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