FrankBro Posted December 4, 2009 Share Posted December 4, 2009 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 More sharing options...
FrankBro Posted December 4, 2009 Author Share Posted December 4, 2009 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 More sharing options...
justsomeguy Posted December 4, 2009 Share Posted December 4, 2009 If you just want to send a query and get the result, you can use the query method to return a result object, and then get the rows from the result object:http://www.php.net/manual/en/mysqli.query.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.