Connect to server database from localhost

时间秒杀一切 提交于 2019-12-01 01:45:39

Your logging has an error is on the following line:

$con = mysqli_connect($host,$user,$pass,$db) or die("Error " . mysqli_error($con));

$con is never assigned a value (base mysqli_connect failed) and you are passing it to mysqli_error().

Try the following instead - it will give you the information you need about why you cannot connect:

$con = mysqli_connect($host,$user,$pass,$db);
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

As user Dagon mentioned, your host string should be something like my-domain.com or even more likely, localhost and not http://www.my-domain.com/phpmyadmin/

if you upload your localhost file to web server, some host provider, use "localhost" too as hostname

$host = 'localhost';
$user = 'u5er';
$pass = 'pa55w0rd';
$db = 'db_name';

"Host 'XXX.XXX.XXX' is not allowed to connect to this MySQL server" appear when you didn't configure host to grant accessing database

Most external databases are connected to via an IP or domain/subdomain with correct port number. You have put "http" which is port 80. Most MySQL are 3306. Your host/extremal provider should have given you an IP of the database server and logon details...

Your IP address must be registered to your host in order to connect to the database

Yes, it's possible to resolve that. Change the variable $host to the right hostname (localhost or other).

To find out if your server allows external connections you can use an online port scan to see if you have the mysql port (default is 3306) open to the outside world.

To define which IP addresses can access your database you should use an firewall rule.

The host string is wrong. A valid mysql URL will be of the form 'mysql://hostname.tld/database'. However its very unusual that administrators make SQL databases available over the internet. Most likely you should try to run your php application from the same server or network as the database server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!