1

How can I connect my localhost PHP files to my remote server MYSQL database?

For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database. How do I do that?

Thanks.

3 Answers 3

2

If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.

For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.


A couple of notes :

  • Your remote host must accept connections to MySQL (think about the firewall)
  • Your remote MySQL database server must accept connections from non-localhost
  • Sending queries, and fetching results, to/from a far away server will be a lot slower than doing so on localhost !
Sign up to request clarification or add additional context in comments.

1 Comment

Is the real remote host the IP Address?
0
mysql_connect(SQL_IP, SQL_NAME, SQL_PASS);

Comments

0

Well when you install Wordpress set the host to be the IP of your remote server. If this isn't what you're looking for, please reword your question. If you're not using word press, check ou the PHP documentation for mysql_connect. The first parameter is the host. Enter the IP or hostname of your remote server here. And then follow that with your username and password.

mysql_connect('remote-host', 'myuser', 'mypassword');

Note: Some hosts do not allow remote connections to MySQL. Check your remote server doesn't have 3306 firewalled or only instructed MySQL to bind it to 127.0.0.1.

1 Comment

what i am looking is i am writing a crm on my localhost but i want that crm to get data from my main remote server that is online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.