Thursday, April 2, 2015

[MySQL][PHP][Resolved] mysql_real_escape_string(): A link to the server could not be established in xxx


Firstly, check which version of PHP you are using at your server.

Since the php function “mysql_real_escape_string” is only works for PHP 4 >= 4.3.0, and PHP5. If your PHP version is not among the version mentioned and newer then that, you should to use the MySQLi or PDO_MySQL extension instead since the extension was deprecated as of PHP 5.5.0.

There is an example , change your “mysql_real_escape_string” :
$content = mysql_real_escape_string($html_content);

To Procedural style
$conn = mysqli_connect(“localhost”,”root”,” password”,”test”);
//<-- This line is for showing where is the value $conn from
$content = mysqli_real_escape_string($conn, $html_content);
Or Object oriented style
$conn = mysqli_connect(“localhost”,”root”,” password”,”test”);
//<-- This line is for showing where is the value $conn from
$content = $conn->real_escape_string ($html_content);
Reference:
http://php.net/mysql_real_escape_string
http://php.net/manual/en/mysqli.real-escape-string.php

No comments :

Post a Comment