I get this error when I try to use mysql_real_escape_string().
Access denied for user 'ODBC'@'localhost' (using password: NO)
I don’t understand why I must be connected to the database to check if the values are OK to insert to MySQL.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is because mysql_real_escape_string takes into account the current character set of the connection. As such, it needs a connection. 🙂
If you don’t want to manually set up a connection in advance, you could set the various MySQL runtime defaults within your .ini file.
However, if you’re using your own database class (or simply the manual commands), it’s often worth establishing the connection early in the lifetime of your script.