Jump to content

Mysqli Fetch_array For Prepared Statements.


FrankBro

Recommended Posts

I recently learned the mysqli extension and love how it's working. I only have 1 problem. Since i love prepared statements, i though i'd write everything with it from now on. The only problem .. the mysqli_result only works for query, which means i can do something like this:

$stmt = $this -> db -> prepare("SELECT `status` FROM `test` WHERE `name` = ?");$stmt -> bind_param('s', $name);$stmt -> execute();$stmt -> bind_result($status);$stmt -> fetch();$stmt -> free_result();$stmt -> close();echo $status;

But i can't do something like this:

$stmt = $this -> db -> prepare("SELECT * FROM `test`");$stmt -> execute();while($row = $stmt -> fetch_row()){	 echo $row['name'].'---'.$row['status'];}$stmt -> free_result();$stmt -> close();

Because the mysqli_result don't apply to prepared statements .. which sucks.Any work around? Or way to deal with that ?

Link to comment
Share on other sites

I got that to work, wondering if there's anything better then that.

$stmt = $this -> db -> prepare("SELECT `id`, `name`, `status` FROM `test`");$stmt -> execute();$stmt -> bind_result($id, $name, $status);while ($stmt->fetch()) {	echo $id.'	 '.$name.'	 '.$status.'<br/>';}$stmt -> free_result();$stmt -> close();

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...