I'm using PHP with MySQL database. The PCs are having a network to each other. My problem is I want to connect to the MySQL database on another computer. I want to store data on that MySQL database from another computer. How could i possibly do on this? Thanks so much for any suggestions.
Set up MySQL as normal on that computer. Then, simply:
<?php mysql_connect('IP of 2nd computer', 'username', 'password'); ?>
Point mysql_connect() to use the other computer's name / IP address:
$server = '192.168.0.3';
$user = "foo";
$password = "bar";
$conn = mysql_connect($server, $user, $password);
You'll need to make sure the DB in the other PC has enough rights to connect from a different host - i.e. your computer.
The MySQL server must be configured to accept connections externally, and its firewall must be configured to allow incoming connections on that port (TCP port 3306). This may or may not already be set up.
You must also account for this in the MySQL permissions as follows.
Often, when setting up your MySQL permissions, you'll set user access rights only for @'localhost'. You'll need to make sure that both the user account and its granted permissions are set for the appropriate hostname or IP address you will be connection from. For example, you could create a new authorised user with:
GRANT ALL PRIVILEGES ON somedatabase.* TO someuser@'somehostname' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
You have to do all of this before you can connect to that server remotely with PHP, using something like this:
mysql_connect('mysqlservername', 'someuser', 'password');