我看到使用mysqli_fetch_object的所有示例使用mysql_query()
,我無法使它與預處理語句一起使用。有人知道這段代碼有什麼問題,因爲fetch_object返回null。是否可以使用mysqli_fetch_object和預處理語句
$sql = "select 1 from dual";
printf("preparing %s\n", $sql);
$stmt = $link->prepare($sql);
printf("prepare statement %s\n", is_null($stmt) ? "is null" : "created");
$rc = $stmt->execute();
printf("num rows is %d\n", $stmt->num_rows);
$result = $stmt->result_metadata();
printf("result_metadata %s\n", is_null($result) ? "is null" : "exists");
$rc = $result->fetch_object();
printf("fetch object returns %s\n", is_null($rc) ? "NULL" : $rc);
$stmt->close();
輸出是:
preparing select 1 from dual
prepare statement created
num rows is 0
result_metadata exists
fetch object returns NULL
當然NUM行應> 0,如果你期待一個非空對象返回? – jcuenod 2009-12-29 19:38:43