Asked  7 Months ago    Answers:  5   Viewed   39 times

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:UsersxampphtdocsPHP_Login_Scriptconfig.php on line 6

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:UsersxampphtdocsPHP_Login_Scriptlogin.php on line 10

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in C:UsersxampphtdocsPHP_Login_Scriptlogin.php on line 11

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:UsersxampphtdocsPHP_Login_Scriptlogin.php on line 15

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:UsersxampphtdocsPHP_Login_Scriptlogin.php on line 16

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:UsersxampphtdocsPHP_Login_Scriptlogin.php on line 19

I'm getting this error above on localhost even if my config file is like this:

<?php

    define("DB_HOST", "localhost");
    define("DB_USER", "root");
    define("DB_PASSWORD", "");
    define("DB_DATABASE", "databasename");

    $db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

?>

This used to work, but now it doesn't anymore. Is there any problem with this code or is it not working now? This is the tutorial I am working on right now.

 Answers

95

That combination of username, host, and password is not allowed to connect to the server. Verify the permission tables (reloading grants if required) on the server and that you're connecting to the correct server.

Wednesday, March 31, 2021
 
Crashthatch
answered 7 Months ago
80

I experienced the exact problem already. According to comments (windows, wamp, mysql), here is a solution to get an export of your database/table(s):

Open CMD and paste this:

cd C:wampbinmysqlmysql15.5.8bin

If your windows is installed into C drive, Then apply your own information in this line and paste it too:

mysqldump -u username -p databasename > filename.sql

Note: username is root by default.


Also you can determine a particular table like following:

mysqldump -u username -p databasename tablename1 tablename2 > filename.sql

Here is an example:

  1. Open CMD
  2. write cd C:wampbinmysqlmysql15.5.8bin
  3. Then write mysqldump -u root -p univercity students > H://TheNameOfStudents.sql
Wednesday, March 31, 2021
 
Crontab
answered 7 Months ago
19

Create or edit your php.ini file and set this variable value in it:

session.gc_maxlifetime = 1440

The integer is in seconds. 500000 seconds is 5.7 days. Then restart apache.

Wednesday, June 16, 2021
 
Fredy
answered 5 Months ago
73

You're at risk of MySQL injections. Never insert data directly to a database without some sort of projection first. It's a major security risk. Also use mysqli_real_escape_string instead, and note that your $_POST[webSite] is unprotected.

Also, your error means that your database details are not correct.

Monday, August 23, 2021
 
LunaLoveDove
answered 2 Months ago
43

First of, I can't imagine the reason why you've deleted root user. But back to the question - you should specify WITH GRANT OPTION, like this:

(However this should be opted after you get the mysql re-installed as if you don't have the root access and the user is not having the sufficient privileges also, then the best is to restart the install process and make the user and grant them privileges the way defined below)

mysql> create user 'golden'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to golden@localhost with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

and then

mysql> select current_user();
+------------------+
| current_user()   |
+------------------+
| golden@localhost |
+------------------+
1 row in set (0.00 sec)

mysql> create database testing;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on testing.* to test;
Query OK, 0 rows affected (0.02 sec)

mysql> drop database testing;
Query OK, 0 rows affected (0.12 sec)

-but yet again, think twice before deleting root user.

Wednesday, October 20, 2021
 
Alan Clark
answered 6 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share