mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-14 00:33:41 +02:00
fix: array type coercion for params in driver (#24)
This commit is contained in:
parent
38fe8e5b82
commit
0235610bfa
1 changed files with 7 additions and 2 deletions
|
@ -13,9 +13,14 @@
|
||||||
parent::__construct(...func_get_args());
|
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
|
// Execute SQL query with optional prepared statement and return array of affected rows
|
||||||
public function exec(string $sql, mixed $params = null): array {
|
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 = [];
|
$res = [];
|
||||||
|
|
||||||
// Fetch rows into sequential array
|
// Fetch rows into sequential array
|
||||||
|
@ -28,7 +33,7 @@
|
||||||
|
|
||||||
// Execute SQL query with optional prepared statement and return true if query was successful
|
// Execute SQL query with optional prepared statement and return true if query was successful
|
||||||
public function exec_bool(string $sql, mixed $params = null): bool {
|
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"
|
return gettype($query) === "boolean"
|
||||||
// Type is already a bool, so return it as is
|
// Type is already a bool, so return it as is
|
||||||
|
|
Loading…
Add table
Reference in a new issue