0

Quick question here, I'm new to web hosting and I'm just having a muck around to see what's what. I've created the following PHP document and hosted it on my free 000webhost domain:

<?php 

$mysql_host = "mysqlXX.000webhost.com"; 
$mysql_database = "***********_people"; 
$mysql_user = "*************_admin"; 
$mysql_password = "******************"; 

// Create connection 
$con=mysqli_connect($mysql_host,$mysql_database,$mysql_user,$mysql_password); 

// Check connection 
if (mysqli_connect_errno($con)) 
  { 
  echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
?>

I have set up (hopefully correctly) a small table in my database with 3 fields:

  1. ID - No Null, auto-increment, integer, primary
  2. First Name - VarChar, Length 20
  3. Last Name - VarChar, Length 20

And entered data for each one. When I open the file from my control panel, I get the following error:

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'a4935911_people'@'10.1.1.45' (using password: YES) in /home/a4935911/public_html/MySQL+PHP.php on line 9

AND

Failed to connect to MySQL: Access denied for user 'a4935911_people'@'10.1.1.45' (using password: YES)

Any ideas, anyone?

5
  • 4
    you username/password is incorrect Commented Oct 17, 2013 at 17:23
  • If your username ends in _admin, then how come the error message says it was …_people …? Commented Oct 17, 2013 at 17:28
  • 2
    Change it to $con=mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database); and it will work. Commented Oct 17, 2013 at 17:39
  • i just want to add up since i think you are just starting up get used to the correct way of connecting to your database seperate your db connection to 1 page only and include it to all the pages cause if you finish your system and its 100pages then you have to edit 100 pages when you upload it Commented Oct 17, 2013 at 17:40
  • This happens because there is no permission set in the database server at mysqlXX.000webhost.com to access the database from your computer's IP using that username. This mistake is pretty common and can be solved very easily using GRANT command. Check my answer. Commented Oct 17, 2013 at 17:41

5 Answers 5

7

Wrong argument sequence here:

$con=mysqli_connect($mysql_host,$mysql_database,$mysql_user,$mysql_password);

Look at the message: Access denied for user 'a4935911_people'@'10.1.1.45' (using password: YES) where a4935911_people is not a user, it is your database's name as set above $mysql_database = "***********_people";.

Use: Host, user, password, dbname as described in the Documentation.

Solution:

$con=mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
Sign up to request clarification or add additional context in comments.

2 Comments

Ahh, I see it now. Yeah, 000webhost gives you the variables in that order so I assumed that was the correct oder to enter them. Thanks for your replies everyone :)
@AndreyVolk Hi there, just asking did you have to wait for a few days to get the connection working? My setup is correct but after two days I am still getting 'Host 10.1.1.25 is not allowed...' Did you faced this issue before?
2
argument sequence is following order.
$host ="localhost" // change to your host 
$username ="root"     // change to your mysql user name by default root 
$pass =" "       //add password if any 
mysql_connect($host,$username,$pass) //don't change the sequence 
mysql_select("test") // create the test database in mysql

Comments

0

Two possible reasons:

  1. Wrong username/password - check it carefully.

  2. You can't connect remotely, connections are allowed only via localhost. Check your hosting website for such information. If it's not allowed, you can do nothing.

Comments

0

In Addition to the possible conclusions that @ElonThan provides...

it's also possible that your username lacks the proper privileges to the database you are connecting to.

1 Comment

I forget about that while writing answer, it's possible to. But solving p.2. from my answer will also solve this problem (one command).
0

You need to set up mysql to allow remote connection for a particular user in the MySQL database server i.e. mysqlXX.000webhost.com here . The default syntax is:

grant <permission> on <database> to <user>@<location> identified by <password>

So here you have to use(as you have specified the parameters)-

grant all on ***********_people.* to '*************_admin'@'10.1.1.45' identified by '******************'

So for your case run the following command- grant all on database_name.* to 'username'@'your_ipaddress' identified by 'password'

Run this command in MySQL command prompt.

This will allow username to connect from your IP using that password and give all permissions on all tables in the specified database.

  • To allow any user to connect from any IP address and use all the tables in any database use the following syntax-

grant all on *.* to '%'@'%' identified by 'password'

And finally you have to use the following command-

FLUSH PRIVILEGES;

To reload all privileges.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.