Page 1 of 1

Fetching an object using mysqli prepared statements

Posted: Sun Aug 23, 2009 10:45 am
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