Jump to content

Best way to return rows from array, prepared statements?


Recommended Posts

Hey guys,

 

I was wondering what is the best way to grab multiple rows from a database using prepared statements? Would it be something similar to this?

 

$stmt = $this->_con->prepare('MY QUERY');
if ($stmt) {
    $stmt->execute();
    $stmt->bind_result($lol, $lol2, $lol3);
    $rows = array();
    while ($stmt->fetch()) {
            $item = array(
                  'lol' => $lol,
                  'lol2' => $lol2
            );
            $rows[] = $item;
    }
    $stmt->close();
    return $rows;
}

 

This seems to work but i want to know if there is any other/better ways of doing it.

 

Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.