According to the documentation:
If the link identifier is not specified, the last link opened by
mysql_connect()
is assumed. If no such link is found, it will try to create one as ifmysql_connect()
was called with no arguments. If no connection is found or established, anE_WARNING
level error is generated.Returns the escaped string, or
FALSE
on error.
An educated guess is that you do not have a valid connection to the database, therefore mysql_real_escape_string
attempts to open a new connection using the configuration values in php.ini
, which fails.
Obligatory security notice:
You are using an obsolete database API and should use a modern replacement. You are also vulnerable to SQL injection attacks that a modern API would make it easier to defend yourself from.