php - mysqli bind_param vs '".$var."'; whats the difference? -
this question has answer here:
i'm trying figure out difference between using prepared statements , and escaping/converting variable string follows:
$sql = "select `user_id`, `user_name` table `user_id` = ? , `user_name`= ?"; $sqlprepare = $conn->prepare($sql); $sqlprepare->bind_param('ss', $user_id, $user_name); $sqlprepare->execute(); $result = $ $sqlprepare->get_result(); if($result->num_rows ===0) { // work }
vs
mysqli::real_escape_string($whatever_vars_needed); $sql = "select `user_id`, `user_name` table `user_id` = '".$user_id."' , `user_name`= '".$user_name."'"; $sqlquery = $conn->query($sql); if($sqlquery->num_rows ===0) { // work }
as far protecting against sql injections go, both serve same purpose? , if so, wouldn't preferred use second method since save bit of typing?
i realize i'm using query vs prepare don't see difference if i'm converting variables strings?
which better method?
since save bit of typing
this quite interesting phenomenon of php subculture.
reason, regular php user have no idea of user-defined functions or other complex control or data structure. therefore, idea of "saving bit typing" rid of "unnecessary" operations safety measures or error reporting.
browsing through php tag on site, may find thousands of short-hands, of them quite smart - reason none of them ever involving user defined functions - raw php functions only.
Comments
Post a Comment