开发者

Is there any difference in these prepared statements using PHP and MYSQL?

$q = $dbc -> prepare ("INSERT INTO accounts (type, username, gender, email, password) VALUES (?, ?, ?, ?, ?)");
$q -> bind_param('sssss', ($_POST['type']), ($_POST['username']), ($_POST['gender']), ($_POST['email']), ($_POST['password']));

$q -> execute();

Compared to;

$type = $_POST['type'];
$username = $_POST['username'];
$gen开发者_运维技巧der = $_POST['gender'];
$email = $_POST['email'];
$password = $_POST['password'];

$q = $dbc -> prepare ("INSERT INTO accounts (type, username, gender, email, password) VALUES (?, ?, ?, ?, ?)");
$q -> bind_param('sssss', $type, $username, $gender, $email, $password);

$q -> execute();

Are there any benefits of doing it either way?

Thanks.


They're both the same, which is better just depends on which you find easier to read and maintain really.


No, these techniques are both identical.


The only difference between these two statements (as far as I can tell) is that you're grabbing the POST variables ahead of time in the second example. This accomplishes nothing unless you need those variables later, or you simply want your code to make a little more sense.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜