Reputation: 2633
My query class isn't working on a clients new server because their server is missing the mysqlnd driver. How would I convert the method to not use mysqlnd and also not screw up all their classes?
function query($query, $params=NULL) {
if($params!=NULL) {
$stmt = $this->mysqli->prepare($query);
//must turn $params into reference array to bind
$ref = array();
foreach ($params as $key => $value) {
$ref[$key] = &$params[$key];
}
call_user_func_array(array($stmt,'bind_param'),$ref);
$stmt->execute();
$result = $stmt->get_result();
} else {
$result = $this->mysqli->query($query);
}
if($result){
$rowArray = array();
while ($myrow = $result->fetch_object()) {
$rowArray[] = $myrow;
}
return $rowArray;
}
return false;
}
Upvotes: 1
Views: 227
Reputation: 157871
A quite similar approach using call_user_func_array()
You can find some solutions in the Comments section on the manual page
I have no idea why mysqli require all this unnecessary toilsome stuff while PDO does it out of the box. Compare your soon-will-be code with this one:
function query($query, $params=NULL) {
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
}
Upvotes: 2