mysqli程序准备好的陈述

时间:2013-10-14 14:01:09

标签: php mysqli sql-injection procedural

我正试图从经典的mysql传递给mysqli ..

我选择使用过程方式而不是面向对象,尽管我在面向对象的方式中找到了更多的例子。

我需要编写代码的一部分,以便在验证方面检查数据是否已存在于DB记录中。

我已经来到这部分代码,它确实有效,但我不太确定,如果我遗漏了某些部分,或者我是否包含了不必要的陈述..

$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似乎有必要临时存储

1 个答案:

答案 0 :(得分:0)

我认为你也不需要。您应该可以使用mysqli_stmt_get_result来获取结果集,然后使用常规结果集函数(例如mysqli_fetch_assoc

相关问题