All the examples I see using mysqli_fetch_object use mysql_query()
, I cannot get it to work with prepared statements. Does anyone know what is wrong with this code snippet, as fetch_object returns null.
$sql = "select 1 from dual";
printf("preparing %s
", $sql);
$stmt = $link->prepare($sql);
printf("prepare statement %s
", is_null($stmt) ? "is null" : "created");
$rc = $stmt->execute();
printf("num rows is %d
", $stmt->num_rows);
$result = $stmt->result_metadata();
printf("result_metadata %s
", is_null($result) ? "is null" : "exists");
$rc = $result->fetch_object();
printf("fetch object returns %s
", is_null($rc) ? "NULL" : $rc);
$stmt->close();
The output is:
preparing select 1 from dual
prepare statement created
num rows is 0
result_metadata exists
fetch object returns NULL
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…