0

I have a website that has a page that needs to show all the information that is in the local MySQL server (not in the hosting). How am I gonna do that?

I only tried to change the connection details but no luck on that matter.

db_connect.php (connect to hosting server)

<?php 
   $servername = "localhost";
   $username = "xxx";
   $password = "yyy";
   $database = "dbdb";

   $conn = new mysqli($servername, $username, $password, $database);

   if($conn->connect_error){
        die("FAILED TO CONNECT : " . $conn->connect_error);
   }
?>

to db_local.php (connect to my local server)

<?php 
   $servername = "192.168.x.xx";
   $username = "";
   $password = "";
   $database = "info";

   $conn = new mysqli($servername, $username, $password, $database);

   if($conn->connect_error){
       die("FAILED TO CONNECT : " . $conn->connect_error);
   }
?>

Is it possible? I only need to do that as a first aid solution in my main problem. I am getting this kind of error:

FAILED TO CONNECT : Can't connect to MySQL server on '192.168.x.xx' (110)

Pang
  • 9,564
  • 146
  • 81
  • 122
MDB
  • 339
  • 4
  • 19

2 Answers2

0

mysql might only accept connections from localhost, if you are connecting to the db from your local computer then you need to change the address to localhost

If you are not connecting to the DB via local machine then you need to make sure that port 3306 is open on the server, selinux is off ( assuming you are on linux ) and that you have the proper credentials.

If that doesnt work edit your my.cnf and change the line bind-address: 127.0.0.1 to the machines local ip.

Camron
  • 63
  • 5