Knowledge base
1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Fix a MySQL error ($ in password)
This guide details the specific rules to follow when creating a user password with mysqli_connect()
that contains the character $
.
Preamble
- If, when using
mysqli_connect()
, you get the error message "Access denied for user" and your database user password contains a$
sign, the issue may be due to the way strings work in PHP.
Rules to follow
When the special character $
is used in a user password and it is followed by any character other than a number, the variable name is not valid and the substitution does not occur correctly.
Here are some solutions to fix this:
- Enclose the password in single quotes:
'$******'
- Ensure that a number directly follows the dollar sign:
"$2*****"
- Use a backslash to "escape" the dollar sign in the password:
“\$****”
Link to this FAQ: