问题
I got this warning message when executing my PHP script in Internet webserver, but in local wamp it is working without warnings. what is the reason ?
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/deport/public_html/abc/index.php on line 209
回答1:
mysql_real_escape_string() needs an active connection to the MySQL server and will initiate one with the default data from the php.ini configuration if there is none.
Do not use this function without first connecting to the database.
Also, do not use the mysql_* functions. They are deprecated and will be removed from PHP.
回答2:
You need to have a valid connection to your MySQL Server first.
Do mysql_connect()
before using this function.
Example:
$connection = mysql_connect("host","user","pass");
mysql_select_db("dbname",$connection);
echo mysql_real_escape_string("string to be escaped",$connection);
You should really use the MySQLi Extension instead of the standard MySQL Extension from PHP.
来源:https://stackoverflow.com/questions/15433057/warning-mysql-real-escape-string-function-mysql-real-escape-string-a-link