From edaa16b89e50d30bd30f3d9f2cf3840e7fd9cef6 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Sun, 10 Mar 2024 12:45:17 +0200 Subject: [PATCH] Updated extended PDO for PHP 8.2. --- _include/src/Pdo/PDO.php | 18 ++++++--- _include/src/Pdo/PDOStatement.php | 64 ++++++++++++++----------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/_include/src/Pdo/PDO.php b/_include/src/Pdo/PDO.php index 775ea50c..1ca2b89c 100644 --- a/_include/src/Pdo/PDO.php +++ b/_include/src/Pdo/PDO.php @@ -1,7 +1,15 @@ connectionParams = [$dsn, $username, $passwd, $options]; } - public function addConnectionCallback(callable $callback) + public function addConnectionCallback(callable $callback): void { $this->connectionCallbacks[] = $callback; } @@ -73,7 +81,7 @@ public function quote(string $string, int $type = \PDO::PARAM_STR): string|false /** * {@inheritdoc} */ - public function exec($statement): int|false + public function exec(string $statement): int|false { $this->connectIfRequired(); diff --git a/_include/src/Pdo/PDOStatement.php b/_include/src/Pdo/PDOStatement.php index 3f221f31..d5901697 100644 --- a/_include/src/Pdo/PDOStatement.php +++ b/_include/src/Pdo/PDOStatement.php @@ -1,11 +1,15 @@ -bindings[$parameter] = $variable; - return parent::bindParam($parameter, $variable, $data_type, $length, $driver_options); + int|string $param, + mixed &$var, + int $type = NativePdo::PARAM_STR, + int $maxLength = null, + mixed $driverOptions = null + ): bool { + $this->bindings[$param] = $var; + return parent::bindParam($param, $var, $type, $maxLength, $driverOptions); } /** * {@inheritdoc} - * @return bool */ - #[\ReturnTypeWillChange] - public function bindValue($parameter, $variable, $data_type = NativePdo::PARAM_STR) + public function bindValue(int|string $param, mixed $value, int $type = NativePdo::PARAM_STR): bool { - $this->bindings[$parameter] = $variable; - return parent::bindValue($parameter, $variable, $data_type); + $this->bindings[$param] = $value; + return parent::bindValue($param, $value, $type); } /** * {@inheritdoc} - * @return bool */ - #[\ReturnTypeWillChange] - public function execute($input_parameters = null) + public function execute(?array $params = null): bool { - if (\is_array($input_parameters)) { - $this->bindings = $input_parameters; + if ($params !== null) { + $this->bindings = $params; } $statement = $this->addValuesToQuery($this->bindings, $this->queryString); $start = microtime(true); - $result = parent::execute($input_parameters); + $result = parent::execute($params); $this->pdo->addLog($statement, microtime(true) - $start); return $result; } - /** - * @param array $bindings - * @param string $query - * @return string - */ - public function addValuesToQuery($bindings, $query) + private function addValuesToQuery(array $bindings, string $query): string { - /** @noinspection TypeUnsafeComparisonInspection */ - $indexed = ($bindings == array_values($bindings)); + $indexed = array_is_list($bindings); foreach ($bindings as $param => $value) { $value = match (true) {