note 126329 added to function.mysql-real-escape-string
| From: | rohankumar dot 1524 at gmail dot com | Date: | Wed, 11 Aug 2021 07:28:03 +0000 |
| Subject: | note 126329 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216770@lists.php.net to get a copy of this message | ||
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
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 2409:4043:48b:2774:b8e7:c45a:9f76:62ad)
----
Manual Page -- https://php.net/manual/en/function.mysql-real-escape-string.php
Edit -- https://main.php.net/note/edit/126329
Del: integrated -- https://main.php.net/note/delete/126329/integrated
Del: useless -- https://main.php.net/note/delete/126329/useless
Del: bad code -- https://main.php.net/note/delete/126329/bad+code
Del: spam -- https://main.php.net/note/delete/126329/spam
Del: non-english -- https://main.php.net/note/delete/126329/non-english
Del: in docs -- https://main.php.net/note/delete/126329/in+docs
Del: other reasons-- https://main.php.net/note/delete/126329
Reject -- https://main.php.net/note/reject/126329
Search -- https://main.php.net/manage/user-notes.php