ConFoo Montreal 2026: Call for Papers

Voting

: seven minus seven?
(Example: nine)

The Note You're Voting On

wapharshitsingh at gmail dot com
4 years ago
just wanted to share here, how we can use prepare statement with the combination of ... operator effectively .
<?php
class Database{
private function
getTypeofValues($string, $value){
if(
is_float($value)){
$string .= "d";
}elseif(
is_integer($value)){
$string .= "i";
}elseif(
is_string($value)){
$string .= "s";
}else{
$string .= "b";
}
return
$string;
}
public function
makeQuery($query, array $values){
$stmt = $this->connection->prepare($query);
$type = array_reduce($values, array($this, "getTypeOfValues"));
$stmt->bind_param($type, ...$values);
$stmt->execute();
$result = $stmt->get_result();
return
$result;
}
}
?>

<< Back to user notes page

To Top