Jump to content

Best way to return rows from array, prepared statements?


jagg3rz

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.