fix: array type coercion for params in driver (#24)

This commit is contained in:
Victor Westerlund 2023-12-26 12:33:38 +01:00 committed by GitHub
parent 38fe8e5b82
commit 0235610bfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,9 +13,14 @@
parent::__construct(...func_get_args());
}
// Coerce input to array
private static function to_array(mixed $input): array {
return is_array($input) ? $input : [$input];
}
// Execute SQL query with optional prepared statement and return array of affected rows
public function exec(string $sql, mixed $params = null): array {
$query = $this->execute_query($sql, $params);
$query = $this->execute_query($sql, self::to_array($params));
$res = [];
// Fetch rows into sequential array
@ -28,7 +33,7 @@
// Execute SQL query with optional prepared statement and return true if query was successful
public function exec_bool(string $sql, mixed $params = null): bool {
$query = $this->execute_query($sql, $params);
$query = $this->execute_query($sql, self::to_array($params));
return gettype($query) === "boolean"
// Type is already a bool, so return it as is