开发者

Is mysql_real_escape_string() necessary when using prepared statements?

开发者 https://www.devze.com 2023-03-11 10:11 出处:网络
For this query, is necessary to use mysql_real_escape_string? Any improvement or the query is fine ? $consulta = $_REQUEST[\"term\"].\"%\";

For this query, is necessary to use mysql_real_escape_string?

Any improvement or the query is fine ?

$consulta = $_REQUEST["term"]."%";

($sql = $db->prepare('select location from location_job where location like ?'));

$sql->bind_param('s', $consulta);
$sql->execute();
$sql->bind_result($location);

$data = array();

while ($sql->fetch()) {
    $data[] = array('label' => $location);
}

The query s开发者_如何学运维peed is important in this case.


No, prepared queries (when used properly) will ensure data cannot change your SQL query and provide safe querying. You are using them properly, but you could make just one little change. Because you are using the '?' placeholder, it is easier to pass params through the execute method.

$sql->execute([$consulta]);

Just be careful if you're outputting that to your page, SQL parameter binding does not mean it will be safe for display within HTML, so run htmlspecialchars() on it as well when outputting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号