Everyone knows that PDO prepare statement helps us prevent SQL injection attack. How about this:
function userQuery($username){
$mysqli->multi_query("
PREPARE stmt1 FROM 'SELECT * FROM user WHERE username=?';
SET @a = '$username';
EXECUTE stmt1 USING @a
");
}
userQuery('Kelvin');
Is this as safe as mysqli or PDO prepare statement?
I'm asking this question because I found these sentences on wiki:
Prepared statements are resilient against SQL injection, because parameter values, which are transmitted later using a different protocol, need not be correctly escaped. If the original statement template is not derived from external input, SQL injection cannot occur.
They mention about parameters are transmitted later with different protocol
. And I don't really understand
this.
How can parameters are transmitted later with different protocol
prevent injection attack?