Prepared Statements - Returning recordset
Posted: Thu Apr 09, 2009 11:28 am
So I'm trying to get into using prepared statements via the mysqli interface, since by all accounts that is the best practice for doing queries now. I'm used to doing this the old fashioned way, and I have a function that simply executes a query and then returns the recordset. I'd like to see how to do this with a prepared statement but I can't figure out how to get it to return the correct thing...
Here's the original function:
Basically, here's the prepared statement version that I've worked up and I'm just trying to figure out what exactly the equivalent of return $query; would be:
Thanks for any help! I appreciate it!
-Jesse
Here's the original function:
Code: Select all
function getPerson($ageMin, $ageMax)
{
$sql = sprintf("SELECT uid AS data, " .
"first_name AS label " .
"FROM person WHERE age >= %d AND age <= %d",
$ageMin, $ageMax);
$query = mysql_query($sql);
return $query;
}
Code: Select all
function getPerson($ageMin, $ageMax)
{
global $mysqli;
$statement = $mysqli->prepare("SELECT uid AS data, " .
"first_name AS label " .
"FROM person WHERE age >= ? AND age <= ?");
$statement->bind_param("ii", $ageMin, $ageMax);
$statement->execute();
//return what?
}
-Jesse