public function execute($data = [])
{
$prebound = $args = [];
for ($unnamed = $i = 0; $i < $this->paramCount; $i++) {
if (isset($this->named[$i])) {
$name = $this->named[$i];
if (array_key_exists($name, $data) && $data[$name] !== []) {
if (\is_array($data[$name])) {
$args[$i] = reset($data[$name]);
unset($data[$name][key($data[$name])]);
} else {
$args[$i] = $data[$name];
unset($data[$name]);
}
} elseif (!isset($this->prebound[$name])) {
if ($data[$name] === []) {
throw new \Exception("Named parameter {$name} is not providing enough elements");
} else {
throw new \Exception("Named parameter {$name} missing for executing prepared statement");
}
} else {
$prebound[$i] = $this->prebound[$name];
}
} elseif (array_key_exists($unnamed, $data)) {
$args[$i] = $data[$unnamed];
$unnamed++;
} elseif (!isset($this->prebound[$unnamed])) {
throw new \Exception("Parameter {$unnamed} for prepared statement missing");
} else {
$prebound[$i] = $this->prebound[$unnamed++];
}
}
return $this->conn()->execute($this->stmtId, $this->query, $this->result->params, $prebound, $args);
}