0

従来の 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
      }

この2行が一番気になる

    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

I don't think you need either, really. You should be able to use mysqli_stmt_get_result to get a result set and then use your regular result set functions (i.e. mysqli_fetch_assoc)

于 2013-10-14T14:15:49.767 に答える