Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql_real_escape_string() A link to the server could not be established

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.

like image 238
ganjan Avatar asked Dec 21 '22 19:12

ganjan


1 Answers

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.

like image 65
John Parker Avatar answered Jan 13 '23 21:01

John Parker