0

I see where I am getting a row of data as a result of executing the stmt (expected).

However, when using the get_result() method to return a mysqli::result, there are no fields in the result instance, (not expected, there should be 5 fields).

What embarrassingly simple aspect of this am I missing?

if ($stmt = $mysqli->prepare("SELECT * FROM teachers WHERE teacher_id = ? LIMIT 1")) {    

    $stmt->bind_param('i', $id);

    $stmt->execute();

    $stmt->store_result();

    // output = 1 (expected)
    echo $stmt->num_rows . "<br />";

    $result = $stmt->get_result();

    // no output, expecting '5'
    echo $result->field_count . "<br />";

    // Close statement object
    $stmt->close();

}
else {
    /* Error */
    die ("Prepared Statement Error: " . $mysqli->error);
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Andrew
  • 15
  • 4
  • Does your `echo $stmt->num_rows;` echo a 1 in this case? – verisimilitude Aug 05 '12 at 05:03
  • Yes, it does. @verisimilitude – Andrew Aug 05 '12 at 05:06
  • Upon further investigation (messing with mysql->query), it appears that mysqli::result does not jive with prepared statements. Can anyone verify my suspicion here? – Andrew Aug 05 '12 at 05:21
  • Does this answer your question? [What is the difference between get\_result() and store\_result() in php?](https://stackoverflow.com/questions/35116807/what-is-the-difference-between-get-result-and-store-result-in-php) – Dharman Apr 04 '20 at 21:37

0 Answers0