note 126329 deleted from function.mysql-real-escape-string by cmb
| From: | cmb@php.net | Date: | Wed, 11 Aug 2021 09:33:26 +0000 |
| Subject: | note 126329 deleted from function.mysql-real-escape-string by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216771@lists.php.net to get a copy of this message | ||
Note Submitter: rohankumar dot 1524 at gmail dot com
----
There is requirement for old projects which are using
mysql_escape_string, and
upgrading the PHP version to 7 and above. Basically this happens in maintenance projects where we
don't know how many files the functions are used in application. We can use
[mysqli.real-escape-string][1] for the function:
If you have a typical connection file like conn.php
$conn = new mysqli($host, $user, $password, $db);
// may be few more lines to handle the $conn
if (!function_exists('mysql_escape_string')) {
function mysql_escape_string($sting){ // if mysql_escape_string not available
return $conn->real_escape_string($string); // escape using the $conn instance
}
}
[1]: https://www.php.net/manual/en/mysqli.real-escape-string.php