- var_dump: documentation ( source)
- implode: documentation ( source)
<?php
$_GET['user_id'] = 3;
$query[] = "select * from preferences user_id = ";
$query[] = $_GET['user_id'];
db_exec($query);
function db_exec(string|array $query_parts)
{
if (is_string($query_parts) && !is_literal($query_parts)) {
throw new \Exception("Cannot use non literal string as query.
Please pass the parts in as an array");
} else {
foreach ($query_parts as $query_part) {
if (is_string($query_part) && !is_literal($query_part)) {
throw new \Exception("non-literal string found [$query_part]");
}
else if (is_int($query_part)) {
// todo - decide if you want to allow this or not.
// I personally wouldn't.
}
else {
// todo - support other types
}
}
var_dump(implode("", $query_parts));
}
// rest of db_exec here...
}