fix: type coercion to list array for params in driver (#25)

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

View file

@ -13,14 +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];
// Coerce input to single dimensional array
private static function to_list_array(mixed $input): array {
return array_values(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, self::to_array($params));
$query = $this->execute_query($sql, self::to_list_array($params));
$res = [];
// Fetch rows into sequential array
@ -33,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, self::to_array($params));
$query = $this->execute_query($sql, self::to_list_array($params));
return gettype($query) === "boolean"
// Type is already a bool, so return it as is