Page 1 of 1

Issue connecting to MySQL from PHP

Posted: Thu Sep 30, 2021 3:05 pm
by Mudloop
Hi,

I created a database and a user.
Database name is admin_wp (entered wp), username is the same.
Password is xyz (not really :) )

Then I do this :
$db = new mysqli('localhost', 'admin_wp', 'admin_wp', 'xyz');

And I get this error :
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'admin_wp'@'localhost' (using password: YES) in ...

Am I supposed to use a different user? I can access phpymyadmin with this user, so I don't know what I'm doing wrong.

Thanks!

Re: Issue connecting to MySQL from PHP

Posted: Thu Sep 30, 2021 3:09 pm
by Mudloop
Also, I tried this :
mysql -u admin_wp -p

And that worked. So no idea why it's not working from my simple PHP script.

Re: Issue connecting to MySQL from PHP

Posted: Thu Sep 30, 2021 3:29 pm
by Mudloop
Tried making a new user :

Code: Select all

grant all on admin_wp.* to 'web'@'%' identified by 'c3cg5yTqXNsJzcq9';
(don't worry, it's a temp password)

Code: Select all

+---------------+-----------+
| user          | host      |
+---------------+-----------+
| admin_default | %         |
| admin_wp      | %         |
| web           | %         |
| web           | 127.0.0.1 |
| admin_default | localhost |
| admin_wp      | localhost |
| phpmyadmin    | localhost |
| root          | localhost |
| roundcube     | localhost |
| web           | localhost |
+---------------+-----------+
(note, made it a couple of times with different host but same password)

Code: Select all

$db = new mysqli('127.0.0.1', 'web', 'admin_wp', 'c3cg5yTqXNsJzcq9');
Result :
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'web'@'localhost' (using password: YES)

Re: Issue connecting to MySQL from PHP

Posted: Thu Sep 30, 2021 5:40 pm
by grayfolk
Mudloop wrote:
Thu Sep 30, 2021 3:29 pm

Result :
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'web'@'localhost' (using password: YES)
Due to official documentation looks like youre wrong with arguments order.

Re: Issue connecting to MySQL from PHP

Posted: Fri Oct 29, 2021 7:14 am
by nbaever3
i got same problem

Re: Issue connecting to MySQL from PHP

Posted: Fri Oct 29, 2021 7:58 am
by grayfolk
nbaever3 wrote:
Fri Oct 29, 2021 7:14 am
i got same problem
Check your database credentials, check arguments order.

Re: Issue connecting to MySQL from PHP

Posted: Wed Jan 19, 2022 6:12 am
by clementishutin
Did the issue resolved after looking into database?