SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    Help needed with MySQLi and result_metadata.

    Here's my current code. From what I understood from the php manual, I think it's right, but I'm probably mistaken. The value in $query run fine in the command line. Where's my error?

    PHP Code:
    $stmt $db->prepare($query);
    $stmt->execute();
    $stmt->store_result();
    $meta $stmt->result_metadata();
    $items = array();
    if (
    $meta->num_rows)
    {
    while (
    $item $meta->fetch_assoc())
    {
    $items[] = $item;
    }

    $meta->close();
    $stmt->close(); 
    </SPAN>

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's here:
    while ($item = $meta->fetch_assoc())
    it should be

    while (($item = $meta->fetch_assoc()))

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Heh, no effect. I tested the mysqli instance, it's fine. I tested the stmt object returned from prepare using instanceof, it's fine. execute returns true, but stmt->num_rows = 0. It should be more. Something is messed up.

    Update:

    learned that num_rows at the metadata level is not set until all rows are fetched. Updated code to the following and it still does not work (even when using the extra set of () as the user above suggested. I tested stmt->num_rows after store_result, and that was correct.

    PHP Code:
     $stmt $db->prepare($query);
    $stmt->execute();
    $stmt->store_result();
    $meta $stmt->result_metadata();
    $items = array();
    while (
    $item $meta->fetch_assoc())
    {
    $items[] = $item;
    }
    $meta->close();
    $stmt->close(); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •