0

When I try to connect to a website database using the code:

$server = "domain";
$login = "username";
$password = "password";
$database = "databasename";
$port = 3307;
$con = mysqli_connect($server, $login, $password, $database, $port);

and have all warnings and errors enabled I get a message saying

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain' (111) in 'path'

however when I change $server to localhost it works fine.

If it is blocking me through php unless I use localhost does anyone know why the HeidiSQL or MySQL Administrator clients can connect using the domain?

Munodi
  • 55
  • 1
  • 5

1 Answers1

0

What I understand from your problem statement, you are unable to connect to MySQL server using domain or IP address. To resolve it, first you need to give database access permission to user. Checkout below sql which will do work for you.

GRANT ALL PRIVILEGES ON `databasename`.* TO 'username'@'domain' IDENTIFIED BY 'password' WITH GRANT OPTION;

Once permissions are granted to user check your MySQL configuration settings. Edit your MySQL confifuration file my.cnf and set nbelow mentioned settings.

Set the bind-address to 0.0.0.0 or comment it out:

bind-address            = 0.0.0.0
OR
# bind-address          = 127.0.0.1
v2solutions.com
  • 1,439
  • 9
  • 8