-1

My MySQL server is running on one PC(xampp).I want to insert data into the MySQL database(remote PC) using PHP script from another PC(client).I have made a website using HTML5 and CSS(client).As PHP runs on server,how do I connect to remote PC using a simple webpage?

AnishLinux
  • 47
  • 1
  • 5
  • 1
    I suggest you simply take a look into the documentation. All of phps mysql extensions and classes offer to directly connect to any mysql server accessible via network by simply configuring the correct network parameters. Take a look at the `mysqli` extension as an example: http://php.net/manual/en/mysqli.quickstart.connections.php In addition you will find countless examples here on SO or out on the internet. – arkascha Dec 19 '15 at 13:19
  • @arkascha in this case should I install xampp on both client and server?.Where should I run the .php which I created – AnishLinux Dec 19 '15 at 13:30
  • 1
    Typically you have a system that executes php (often called the "server") and a system that accesses the php scripts via http (often called a "client", or a browser). You never implement a direct access from client to database. That would be a security and performance nightmare. You use the php scripts as central logic and gateway to communicate between client and database. – arkascha Dec 19 '15 at 13:43
  • @arkascha....Thanks!! – AnishLinux Dec 19 '15 at 13:47

1 Answers1

1

You can connect to a mysql database from anywhere using php. Just change the location to point to the remote server.

$servername = "ip_of_remote_server";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

But you have to configure the mysql server to allow remote connections if you are using the root user. See: How to allow remote connection to mysql

Community
  • 1
  • 1
DustinPianalto
  • 373
  • 1
  • 8