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.
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.
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.
Because escaping depends on the character set on the server. See mysql_real_escape_string in the MySQL manual (the PHP function of the same name is just a wrapper around this C function).
find and delete
mysql_close();
this function disconnect completely from MySQL server