0

我正在尝试从经典 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似乎是必要的,对于临时存储似乎是必要的..

4

1 回答 1

0

我认为你也不需要,真的。您应该能够使用mysqli_stmt_get_result获取结果集,然后使用常规结果集函数(即mysqli_fetch_assoc

于 2013-10-14T14:15:49.767 回答