<?php
//sql hard in code for now (generated sql normally
//var_dump of type shows 'ss' => string(2) "ss"
//var dump of $params shows: array(2) { [0]=> string(7) "renault" [1]=> string(20) "Alaskan" }
//SQL ERROR :
//Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
public function getSomething(string $sql, string $type, array $params): array {
$result = array();
$statement = $this->connection->prepare($sql);
$sql = "SELECT * FROM housemark WHERE merk LIKE ? AND (model LIKE ?) GROUP BY form ORDER BY form";
if ($statement) {
//call_user_func_array(array(&$statement, 'bind_param'), makeValuesReferenced($params));
var_dump(makeValuesReferenced(array("mark1", 'model1')));
//neither of this one works
//$statement->bind_param($type, makeValuesReferenced($params));
// $statement->bind_param("ss", makeValuesReferenced(array("renault", 'alaskan')));
if ($statement->execute()) {
$statement->store_result();
var_dump($statement);
if ($statement->num_rows >= 1) {
$statement->bind_result($id, $mark, $model, $form);
while ($rij = $statement->fetch()) {
$result[] = new Housemark($id, $mark, $model, $form);
}
}
}
}
var_dump($this->connection->error);
return $result;
}
function makeValuesReferenced(array $arr): array {
$refs = array();
foreach ($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}