Fetching an object using mysqli prepared statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PeteClimbs
Forum Newbie
Posts: 2
Joined: Sun Aug 23, 2009 9:33 am
Location: Saranac Lake, New York

Fetching an object using mysqli prepared statements

Post by PeteClimbs »

With the usual MySqli I can do:

$the_year=$_GET['y'];
$rslt=$db->query("SELECT * FROM cars where year=$the_year");
while($oAuto=$rslt->fetch_object('MyCarClass')) {
doSomething($oAuto);
}

But, I would like to do something like this (parts omitted):

$stmt->prepare('SELECT * FROM cars WHERE year=?');
... bind_param(..);
$stmt->bind_result($oCar);
while (stmt->execute()) {
$stmt->fetch();
.....
}

Is that possible? If so, where would I put my class name -- in the first param of bind_result?
Or perhaps $oCar= fetch('MyCar')?
Or???

TIA,
Pete
Post Reply