I know there are a lot of threads asking this question already, but I have been at this for hours and am at wits end. I am attempting to connect to a MySQL database that I am running of my MacBook with the following PHP:
<?php
DEFINE('DB_USER', 'webuser');
DEFINE('DB_PASSWORD', 'thispassword');
DEFINE('DB_HOST', '127.0.0.1:3306');
DEFINE('DB_NAME', 'learning_accounts');
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Error connecting: ' .
mysqli_connect_error()
);
?>
That returns the following error:
Error connecting: Access denied for user 'webuser'@'localhost' (using password: YES)
I can connect fine through the terminal, even trying to connect with PHP and root does not work. I am new to both PHP and MySQL so any guidance and insight would be appreciated!
I have tried tons of solutions such as granting privileges, flushing privileges, creating new users, using PDO, nothing has been working - please help!
Thanks so much, I hate learning new languages because then I'm a lost fish when it comes to debugging at first!
Update
I have a password set for my root account, but changing the DB_PASSWORD variable to '' changes the error to: Error connecting: Unknown database 'learning_accounts'
Update 2 I have fixed the issue, check my answer to see how, if you are having this problem then I hope you found this thread quickly!
- Zach L