多次查询后,PHP stmt准备失败

时间:2016-01-18 00:31:58

标签: php mysqli prepared-statement

  

警告:mysqli_stmt_bind_param()要求参数1为mysqli_stmt,第64行给出布尔值

我发现了其他多个有这个问题的帖子,但我尝试过的解决方案没有什么区别。 像stmt_close()stmt_free()这样的事情没有什么区别。

所以这是我的实际代码片段:

第一次准备并执行:

// Connect to database
$mysqliID = mysqli_connect($mysqliHost, $mysqliUsername, $mysqliPassword);
if (!$mysqliID) throw new Exception("");
if (!mysqli_select_db($mysqliID, $mysqliDB)) throw new Exception("");

// Check if the username or email address aren't already accupied.
$stmt = mysqli_prepare($mysqliID, "SELECT id FROM Account WHERE username=? OR email=?");
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
if (!mysqli_stmt_execute($stmt)) throw new Exception("");
$duplicates = 0;
mysqli_stmt_bind_result($stmt, $duplicateid);
while (mysqli_stmt_fetch($stmt))
{
    die ("error:-gebruikersnaam of email al in gebruik.");
}

第二次准备并执行:

// Save account with salted and hashed password.
include "PasswordHash.php";
$hashResult = create_hash($password);
$hashResultSplitted = explode(":", $hashResult);

$salt = $hashResultSplitted[2];
$hash = $hashResultSplitted[3];
$verified = 0;
$stmt = mysqli_prepare($mysqliID, "INSERT INTO Account (username, hash, salt, email, verified) VALUES (?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssssi", $username, $hash, $salt, $email, $verified);
if (!mysqli_stmt_execute($stmt)) throw new Exception("");

第3次,最后准备并执行:

// Save verification token.
$token = bin2hex(random_bytes(16));
$expirationtime = time() + (15 * 60);
$accountid = mysqli_insert_id($mysqliID);
$stmt = mysqli_prepare($mysqliID, "INSERT INTO Verifications (token, expirationtime, accountid) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sii", $token, $expirationtime, $accountid);
if (!mysqli_stmt_execute($stmt)) throw new Exception("");

因此,在第3个和最后一个代码块中,我在mysqli_prepare上收到警告,但前两个代码已成功完成。

解决方案: 原来名为Verifications的表应该是Verification。通过良好的阅读和照顾我找到了一些睡眠。

0 个答案:

没有答案