我有一个PHP文件,该文件通过POST请求获取JSON格式的数据。
我正在使用准备好的语句,并且一切正常,直到调用mysqli_fetch_assoc
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,在C:\ xampp \ htdocs \ LoanAppTest \ login.php第31行中给出的布尔值
这仅在我声明
mysqli_stmt_execute($stmt);
时发生,如果我将其注释掉,则会得到我想要的结果,但是我需要mysqli_stmt_execute($stmt);
才能使$count = mysqli_stmt_num_rows($stmt);
正常工作。这是我的代码:
if($jsonobj == null){
header("Location: http://localhost/dashboard");
} else {
include "config.php";
$obj = json_decode($jsonobj, true);
$clientID = (int)$obj['prop_ClientID'];
$query = "SELECT ClientID, FirstName, LastName, MiddleName, ContactNo FROM tblClient WHERE ClientID = ?";
// Initialize prepared statement
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $query)) {
echo "SQL Statmenet Failed.";
} else {
// Bind parameters and execute statement
mysqli_stmt_bind_param($stmt, "i", $clientID);
mysqli_stmt_execute($stmt);
// Store result and count for validation (check if ClientID exists)
mysqli_stmt_store_result($stmt);
$count = mysqli_stmt_num_rows($stmt);
if ($count == 0) {
echo "No Client ID in DB";
} else {
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result); // This part returns the error
print_r($row);
}
}
}
我有一个PHP文件,该文件通过POST请求获取JSON格式的数据。我正在使用准备好的语句,并且一切正常,直到调用mysqli_fetch_assoc警告:mysqli_fetch_assoc()期望...