I'm trying to write a prepared select query function for my DB-class. I think from the code below you can understand what I want to do but obviously this code doesn't work. How can do it right?
public function preparedSelectQuery($sql, $types){
if(func_num_args() < 3){
throw new Exception("Less than 3 args!");
}
$stmt = $this->mysqli->stmt_init();
if (!$stmt->prepare($sql)) {
throw new Exception("Failed to prepare statement!");
} else {
if($stmt->bind_param($types, func_get_args())){
if($stmt->execute()){
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$dataset[] = $row;
}
$result->close();
$stmt->close();
return $dataset;
}else{
throw new Exception("Failed to execute!");
}
}else{
throw new Exception("Failed to bind parameters!");
}
}
}