logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: PHP connect Error 1044
Author
laurbest



Joined: 20 Aug 2021
Posts: 2
Location: Iasi

PostPosted: Sat 21 Aug '21 19:27    Post subject: PHP connect Error 1044 Reply with quote

Hi!I tried to connect a PHP script to a database(called eu).I checked all privileges for user root,the one I use in PHP ,but I get this error:

Code:

Array (
    [0] => Array (
        [errno] => 1044
        [sqlstate] => 42000
        [error] => Access denied for user ''@'localhost' to database 'eu'
        )
    )
1


Code:

?php
/* db.php contains these $dbname = "eu";
$dbusername = "root";
$dbpassword = "";
$dbsrvname = "localhost";*/


include('..\db.php');
$con = mysqli_connect($dbsrvname, $dbusername, $dbpassword, $dbname);
if (!$con){
  echo('Connection ERROR');
  die(print_r(mysqli_error($con)));
}
$query="USE eu";
$stms=mysqli_query($con,$query);
$x=$_POST['username'];
$y=$_POST['password'];

if ($stms === false){
  echo('ERROR during query execution: ');
  die(print_r($con->error_list));
}
$row = mysqli_fetch_array($stms, MYSQLI_ASSOC);
if ($row){
  die('Logged in');
}
else{
  die('Wrong username or password');
}
?>


Mod note: added code tags
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Mon 23 Aug '21 3:11    Post subject: Re: PHP connect Error 1044 Reply with quote

$con = mysqli_connect($dbsrvname, $dbusername, $dbpassword);
try
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 23 Aug '21 8:58    Post subject: Reply with quote

MySQL Error 1044 is access denied for the user.
Either the user password combination is not correct or the hostname in the MySQL user table is a different one than expected.
Back to top
laurbest



Joined: 20 Aug 2021
Posts: 2
Location: Iasi

PostPosted: Tue 24 Aug '21 19:40    Post subject: I looked into user table and it was all fine. Reply with quote

James Blond wrote:
MySQL Error 1044 is access denied for the user.
Either the user password combination is not correct or the hostname in the MySQL user table is a different one than expected.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 149
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Wed 25 Aug '21 20:39    Post subject: Reply with quote

Good evening,

why is the user's name empty in the error-message?
Code:
Access denied for user ''@'localhost' to database 'eu'

Normally there should be the username you used for trying to get access to the database.
For debugging-purpose try to output $dbusername before you use mysqli_connect - just to be sure that the variable is set correctly. Do the same for the other variables used in mysqli_connect.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Aug '21 9:15    Post subject: Re: I looked into user table and it was all fine. Reply with quote

laurbest wrote:
James Blond wrote:
MySQL Error 1044 is access denied for the user.
Either the user password combination is not correct or the hostname in the MySQL user table is a different one than expected.


It might be that the user on MySQL is

user @ localhost or user @ % (wildcard)

e.g.
Code:

MariaDB [mysql]> SELECT user,host FROM user;
+----------+-----------+
| User     | Host      |
+----------+-----------+
| backup   | %         |
| root     | 127.0.0.1 |
| root     | ::1       |
| backup   | localhost |
| pma      | localhost |
| root     | localhost |
+----------+-----------+
7 rows in set (0.001 sec)

MariaDB [mysql]>


And your error message shows that there wasn't a user same set.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Thu 26 Aug '21 9:20    Post subject: Reply with quote

Also instead of print_r use var_dump

There is a "1" that might be a boolean true.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 149
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 26 Aug '21 13:26    Post subject: Reply with quote

James Blond wrote:
There is a "1" that might be a boolean true.

This "1" is the "true"-result of print_r printed by die(...), because print_r was used without the second parameter set to "true"
print_r-documentation: https://www.php.net/manual/de/function.print-r.php

To circumwent this "problem" either add a true as in
Code:
die(print_r(mysqli_error($con), true));

or put the print_r or var_dump before the die():
Code:
var_dump(mysqli_error($con));
die();


But this is not related to the original problem of not being able to access the database.
Back to top


Reply to topic   Topic: PHP connect Error 1044 View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner