I am trying to connect to my db using php following is my connection string.
$con = mysqli_connect("localhost","almawakeb_khawaneej","******");
mysqli_select_db($con, "moodle_amsk_2018");
if (mysqli_connect_errno())
{
die('Could not connect: ' . mysqli_connect_error(). mysqli_connect_errno().'');
}
else {
die('Connection success');
}
But what I am getting is
Could not connect: Access denied for user 'almawakeb_khawaneej'@'localhost' (using password: YES)1045
When I checked privileges for that user
mysql> SHOW GRANTS FOR 'almawakeb_khawaneej'@'localhost';
+-----------------------------------------------------------------------------------+
| Grants for almawakeb_khawaneej@localhost |
+-----------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'almawakeb_khawaneej'@'localhost' |
| GRANT ALL PRIVILEGES ON `moodle_amsk_2018`.* TO 'almawakeb_khawaneej'@'localhost' |
+-----------------------------------------------------------------------------------+
It has all necessary privileges. Password is also correct because it is working for yii2 framework config file, that is in the same server.
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.23-0ubuntu0.16.04.1 |
+-------------------------+
What should be the issue ?
EDIT
Resolved ! Actual problem was $
in the password, you can't use string password in the connection string if it contains $
. Declare password as a variable.
$password = '***$***';