0

What I'm trying to do is connecting to server database from localhost.

$host = 'http://www.my-domain.com/phpmyadmin/';
$user = 'u5er';
$pass = 'pa55w0rd';
$db = 'db_name';

$con = mysqli_connect($host,$user,$pass,$db) or die("Error " . mysqli_error($con));
$sql = "SELECT col FROM test WHERE id = '1'";

$result = mysqli_query($con,$sql);

Errors

Warning: mysqli_connect(): in C:\xampp\htdocs\sp_concord\cenova_nabidka\page\vytvor.php on line 362

Warning: mysqli_connect(): in C:\xampp\htdocs\sp_concord\cenova_nabidka\page\vytvor.php on line 362

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\sp_concord\cenova_nabidka\page\vytvor.php on line 362
Error

Is it possible to resolve it? How to find out if my server allows external connections? And how to define from which IP addresses it should allow access to database?

Thank you for any suggestion.

EDIT: Ok, I have changed the host to my-domain.com and now it reports the following errors. My IP has no acces to MySQL server...

Warning: mysqli_connect(): (HY000/1130): Host '88.146.210.54' is not allowed to connect to this MySQL server in C:\xampp\htdocs\sp_concord\cenova_nabidka\page\vytvor.php on line 362
Failed to connect to MySQL: Host '88.146.210.54' is not allowed to connect to this MySQL server
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\sp_concord\cenova_nabidka\page\vytvor.php on line 368
1
  • 1
    very unlikely that host string is correct. phpmyadmin is NOT a data base Commented May 25, 2014 at 23:32

6 Answers 6

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I tried to configure an access to dababase for my IP address, but with no success yet. As soon as I have time for this, I will fix it. Thank you.
1

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/

3 Comments

Is the MySQL database running on the same server the PHP script? In that case you can just change the host to localhost instead of my-domain.com. If it's not you will need to configure MySQL to allow connections from remote machines - take a look at the link here: stackoverflow.com/questions/8348506/…
No, it's not and I'm going to check your suggestions. Thank you.
Prosim :). BTW, here's a better link: rackspace.com/knowledge_center/article/…
1

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...

Comments

1

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

1 Comment

What do you mean by "must be registered to your host"?
1

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.

Comments

0

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.

1 Comment

Hi, thank you, but it's not possible. This is local application and I need to use some data from server my-domain.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.