Click here to Skip to main content
15,668,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

Im getting the error
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'map1user'@'localhost' (using password: YES) in C:\xampp\htdocs\projectgmaps\config.php on line 7


Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\projectgmaps\config.php on line 7
Not connected : Ah sh*t

config.php file:
$host = "localhost"; 
$user = "map1user";
$password = "map1password";
$database = "map1";

$connection = mysqli_connect ($host, $user, $password) or die('Not connected : Ah sh*t ' . mysqli_error());


function parseToXML($htmlStr)
return $xmlStr;

// Opens a connection to a MySQL server
//$connection=mysqli_connect ('localhost', 'username', 'password');
//if (!$connection) {
//  die('Not connected : Ah sh*t ' . mysqli_error());

// Set the active MySQL database
$db_selected = mysqli_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysqli_error());

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysqli_query($query);
if (!$result) {
  die('Invalid query: ' . mysqli_error());

header("Content-type: text/xml");

// Start XML file, echo parent node
echo "<?xml version='1.0' ?>";
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
  // Add to XML document node
  echo '<marker ';
  echo 'id="' . $row['id'] . '" ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
  $ind = $ind + 1;

// End XML file
echo '</markers>';


I'm actually following the guide by google on

But its giving me those errors. Does anyone know why? (Im on the Checking the XML output bit using the echo option)

What I have tried:

Ive tried typing the usernames and passwords in directly and via variable.
Ive tried moving the mysqli connect function to the config file instead
Ive tried creating a new database, a new user, a new table.

I cant get this working.

Any help appreciated!
Updated 9-Feb-21 10:35am
Simon_Whale 20-Mar-18 10:06am    
have you tried connecting directly to mysql with the username and passwords supplied?
Member 13736800 20-Mar-18 10:18am    
I'm new to this - sorry - how would I go about doing that?
Simon_Whale 20-Mar-18 10:19am    
Jochen Arndt has a great answer for you to follow.
Baraka Mgamba 2hrs 20mins ago    
Baraka Mgamba 2hrs 20mins ago    

The first one is quite clear:
You have passed invalid credentials (user name and/or password) when trying to connect to the database. What to pass can't be answered here because only you (the database administrator) would know about the existing user accounts.

To add an user account to a MySQL database see MySQL :: MySQL 5.7 Reference Manual :: 6.3.2 Adding User Accounts[^]. This requires connecting as root and providing the root password if one has been set.

The second is a result of the first and of using the wrong error function. For mysqli_connect(), you have to call PHP: mysqli::$connect_error - Manual[^] instead of mysqli_error() upon errors:
$connection = mysqli_connect ($host, $user, $password) or die('Not connected : Ah sh*t ' . mysqli_connect_error());
Share this answer
Member 13736800 20-Mar-18 11:38am    
Jochen -
I already created a user accounts. It's just not accepting them as a login?
Jochen Arndt 20-Mar-18 11:52am    
So you can use them with mysql on the command line as suggested by Simon?
If yes, it should also work with PHP (provided passing the correct database name).

If not check the privileges for the user account(s). See the MySQL link from my answer and The user must have access to your map1 database.
Member 13736800 20-Mar-18 12:15pm    
I am using phpmyadmin which is mariaDB. Is this MySQL manual (with code inside) still applicable? It comes up "wrong syntax" and errors when I try to use any code
Jochen Arndt 20-Mar-18 12:37pm    
Then you have to check the MariaDB documentation for using their command line interface or use PhpMyAdmin to check and configure your database.
This error comes because you are using the wrong Database, Username or Password.
If you are the Database Administrator, you can go to your cPanel and check the Database, Username, and Password and mention correct information. 
One more thing to remember that the user should be connected to the same database and also have All Privileges. 
Share this answer
Ketzalkoatl Rosas A 8-May-20 21:33pm    
Excellent answer. When creating the user it has a prefix midatabase_nombreurs. Just add the prefix. Thank you.
I had this same issue.

First check under "User Accounts" in your phpMyAdmin.

Under "Password" it should say "No" or "Yes" next to the "User name".

If the username you're trying to connect to says "No" for the password, what is happening is you're entering a password when one isn't required to connect.

If it says "Yes" that you're entering the wrong password for the username you're trying to connect.

In your .php file where you created your variable for password, leave it blank with empty strings...if the password field says "No".

For example,

$password = '';
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900