1

quick mysql question. I'm new at php/mysql and followed a tutorial(php/mysql for dummies) so I don't really know what I did wrong or if the tutorial is wrong.

I have a file, "database_connections.inc", that looks like this:

<?php
$user = "username";
$host = "host";
$password = "password";
$database = "database";
?>

With the actual credentials not included for obvious reasons.

Then in another file, login.php, I have:

include("database_connections.inc");
$cxn = mysqli_connect($host,$user,$password,$database)
or die("Query died: Couldnt connect to server.");

I get an error message with the "or die" text, accompanied by a warning:

host xxxxx.000webhost.com is not allowed to connect to this mysql server in....

Why not? I'm sure my credentials are all correct.

I've read in a few places to run some shell statements...but can't really do that, I'm on Windows.

I'm using phpMyAdmin, so hopefully I can do something from there?

Andrei
  • 42,814
  • 35
  • 154
  • 218
user2763424
  • 69
  • 2
  • 8
  • Most MySQL servers are configured that they only accept local connections, so unless your `$host` is `localhost`, it probably won’t work. This is for security reasons btw. and unless you have really good reasons, and a good security system, you shouldn’t change that. – poke Mar 01 '14 at 03:22
  • possible duplicate of [Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server](http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) – Mike Mar 01 '14 at 03:24
  • Where is your code running at and where is the database at? – Prix Mar 01 '14 at 03:24
  • http://www.techdreams.org/mysql-database-server/fixing-the-error-host-xxxxxxxxx-is-not-allowed-to-connect-to-this-mysql-server/2240-20090411 – Nagaraj S Mar 01 '14 at 03:28
  • Host should be `xxxxx.000webhost.com` and not "host" or "localhost". I am familiar with that server. – Funk Forty Niner Mar 01 '14 at 04:34

2 Answers2

1

Open "database_connections.inc" and change it to look like this:

<?php
$user = "root";
$host = "localhost";
$password = "";
$database = "test";
?>

MySQL is by default configured to work with localhost (or 127.0.0.1), in order to allow "host xxxxx.000webhost.com" as host, open phpMyAdmin and select "SQL" and execute this query;

GRANT ALL ON your_database_name.* TO your_user@your_host_xx.xxx.xx.xx IDENTIFIED BY 'your_password'; 
Faisal Ameer
  • 416
  • 5
  • 13
0

Go into PHPMyAdmin, and edit your user.

Under Login Information, there should be an option for "Host"- try adding xxxxx.000webhost.com.

caitlin
  • 2,769
  • 4
  • 29
  • 65