【发布时间】:2013-10-22 02:58:35
【问题描述】:
我正在尝试从经典 mysql 传递到 mysqli..
我选择使用过程方式而不是面向对象,尽管我在面向对象的方式中找到了更多的例子..
我需要编写一部分代码,在验证方面我将检查一个值是否已经在数据库记录中。
我已经来到这部分代码,它确实有效,但我不太确定,如果我遗漏了某些部分,或者我是否包含了不必要的语句..
$con = mysqli_connect("localhost","username","password","db");
// Check connection
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$stmt = mysqli_prepare($con, "SELECT email FROM table WHERE email= ? ");
mysqli_stmt_bind_param($stmt, 's', $email);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($result);
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) > 0) {
some code
}
else {
some other code
}
我最关心这两行
mysqli_stmt_bind_result($result);
mysqli_stmt_store_result($stmt);
尤其是
mysqli_stmt_bind_result($result);
感觉没有必要,而
mysqli_stmt_store_result($stmt);
根据php.net似乎是必要的,临时存储似乎是必要的..
【问题讨论】:
标签: php mysqli sql-injection procedural