本文介紹了在不綁定的情況下使用 PDO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
$stmt = $conn->prepare('SELECT * FROM users WHERE user_id = :user_id');
$stmt->execute(array(':user_id' => $_GET['user_id']));
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
我正在使用這樣的 PDO,我需要清理 GET 參數嗎?
I'm using PDO like that, do I need to sanitise GET parameter?
我知道如果我做 $stmt->bindParam(':user_id', $_GET['user_id'], PDO::PARAM_INT);
不是問題.但我的路安全嗎?
I know if I do $stmt->bindParam(':user_id', $_GET['user_id'], PDO::PARAM_INT);
than it is not a problem. But is my way safe?
推薦答案
是的,它很安全.execute
和 bind*
之間的唯一區別是:
Yes, it's safe. The only differences between execute
and bind*
are:
execute
一次接受多個參數,而您必須bind*
單獨地bind*
每個參數bind*
允許您指定參數類型,而execute
將所有內容綁定為字符串
execute
accepts several parameters at once, while you have tobind*
each one individuallybind*
allows you to specify the parameter type, whileexecute
binds everything as strings
將參數傳遞給execute
主要是一種方便的速記,它仍然是安全的.
Passing parameters to execute
is mostly a convenience shorthand, it's still safe.
這篇關于在不綁定的情況下使用 PDO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!