Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-25 21:13:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!