I used following logic to prepare statements, It handles both Values and Arrays ( taking help from bohwaz note) :
<?php
function getArgType($arg) {
switch (gettype($arg)) {
case 'double': return SQLITE3_FLOAT;
case 'integer': return SQLITE3_INTEGER;
case 'boolean': return SQLITE3_INTEGER;
case 'NULL': return SQLITE3_NULL;
case 'string': return SQLITE3_TEXT;
default:
throw new \InvalidArgumentException('Argument is of invalid type '.gettype($arg));
}
}
foreach ($params as $index => $val) {
// indexing start from 1 in Sqlite statement
if (is_array($val)) {
$ok = $stmt->bindParam($index + 1, $val);
} else {
$ok = $stmt->bindValue($index + 1, $val, getArgType($val));
}
if (!$ok) {
throw new Exception("Unable to bind param: $val");
}
}
?>