简体   繁体   中英

mysqli_real_escape_string with array_map

I'm trying to sanitize $_POST data with array_map and mysqli_real_escape_string

the problem is that when I use the $link variable inside of array_map is it somehow gets converted to a string, I'm pretty sure I have the syntax right, but this one has been knawing at me for a while.

here is my (simplified) code:

$link = mysqli_connect($host, $user, $password);
$row = array_map('mysqli_real_escape_string', $row, array($link, $row));

While everybody recommends PDO, if you do wish to use the mysqli class to achieve what you wanted you need to pass the mysqli link and real_escape_string property to the array_map as an array like so:

$link = mysqli_connect($host, $user, $password);
$escaped_row = array_map(array($link, 'real_escape_string'), $row);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM