From e8ecbdc0ee5037ede2f8dd7a818a7053f0755fc5 Mon Sep 17 00:00:00 2001 From: Damien Date: Mon, 7 Feb 2022 22:14:18 +1300 Subject: [PATCH 01/10] Update Constants.php Update `_isNULL` and `_notNULL` constants to allow checks to run correctly --- lib/Constants.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Constants.php b/lib/Constants.php index 0648011f..c24c1f3c 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -39,8 +39,8 @@ \define('_BETWEEN', 'BETWEEN'); \define('_notBETWEEN', 'NOT BETWEEN'); - \define('_isNULL', 'IS NULL'); - \define('_notNULL', 'IS NOT NULL'); + \define('_isNULL', 'IS'); + \define('_notNULL', 'IS NOT'); \define('_BOOLEAN_OPERATORS', [ '<', '>', '=', '!=', '>=', '<=', '<>', 'IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT' From 741dc53593214475735d8c185452e7545213cec7 Mon Sep 17 00:00:00 2001 From: Damien Date: Mon, 7 Feb 2022 22:18:22 +1300 Subject: [PATCH 02/10] Update ezFunctions.php Uppercased right expression for type consistency specific to these methods in `isNull` and `isNotNull` --- lib/ezFunctions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 5839664a..bdc29c74 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -353,7 +353,7 @@ function gte($x, $y, $and = null, ...$args) * * @return array */ - function isNull($x, $y = 'null', $and = null, ...$args) + function isNull($x, $y = 'NULL', $and = null, ...$args) { $expression = array(); \array_push($expression, $x, \_isNULL, $y, $and, ...$args); @@ -370,7 +370,7 @@ function isNull($x, $y = 'null', $and = null, ...$args) * * @return array */ - function isNotNull($x, $y = 'null', $and = null, ...$args) + function isNotNull($x, $y = 'NULL', $and = null, ...$args) { $expression = array(); \array_push($expression, $x, \_notNULL, $y, $and, ...$args); From e690998268aa4d30353898bf1965f74250b48bf2 Mon Sep 17 00:00:00 2001 From: Damien Date: Mon, 7 Feb 2022 22:24:42 +1300 Subject: [PATCH 03/10] Update ezFunctionsTest.php Fix tests --- tests/ezFunctionsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index cf685cc2..bee8b52b 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -174,13 +174,13 @@ public function testGte() public function testIsNull() { $this->assertIsArray(isNull('field')); - $this->assertArraySubset([2 => 'null'], isNull('field')); + $this->assertArraySubset([2 => 'NULL'], isNull('field')); } public function testIsNotNull() { $this->assertIsArray(isNotNull('field')); - $this->assertArraySubset([2 => 'null'], isNotNull('field')); + $this->assertArraySubset([2 => 'NULL'], isNotNull('field')); } public function testLike() From 5eb046802e6eb5a41af48ed42649ada5634f635b Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 25 Apr 2022 13:45:50 -0400 Subject: [PATCH 04/10] removed global keyword usage, test under PHP 8.1 - use separate class for internal global variables - removed `setInstance` - corrections for multi tag database instances - start testing under PHP 8.1 on Linux GitHub Action --- .github/workflows/ezsql-linux.yml | 2 +- composer.json | 4 +- lib/Database.php | 18 +++++---- lib/Database/ez_mysqli.php | 8 ++-- lib/Database/ez_pdo.php | 8 ++-- lib/Database/ez_pgsql.php | 8 ++-- lib/Database/ez_sqlite3.php | 8 ++-- lib/Database/ez_sqlsrv.php | 8 ++-- lib/Db.php | 66 +++++++++++++++++++++++++++++++ lib/ezFunctions.php | 66 ++++++++++--------------------- lib/ezResultset.php | 14 ++++--- tests/ezFunctionsTest.php | 6 --- 12 files changed, 130 insertions(+), 86 deletions(-) create mode 100644 lib/Db.php diff --git a/.github/workflows/ezsql-linux.yml b/.github/workflows/ezsql-linux.yml index 1806c29d..c444c550 100644 --- a/.github/workflows/ezsql-linux.yml +++ b/.github/workflows/ezsql-linux.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-18.04] - php-versions: ['7.4', '8.0'] + php-versions: ['7.4', '8.0', '8.1'] steps: - name: Checkout diff --git a/composer.json b/composer.json index d28eda0a..49262b9c 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "issues": "https://github.com/ezSQL/ezSQL/issues" }, "require": { - "php": "^7.1 || ^8", + "php": ">7.1", "psr/container": "^1.0" }, "provide": { @@ -55,7 +55,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^6 || ^7 || ^8" + "phpunit/phpunit": "^6 | ^7 | ^8" }, "autoload-dev": { "psr-4": { diff --git a/lib/Database.php b/lib/Database.php index a2e906c9..4baf5e72 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -4,8 +4,8 @@ namespace ezsql; +use ezsql\Db; use ezsql\DInjector; -use function ezsql\functions\setInstance; class Database { @@ -15,7 +15,10 @@ class Database * @var float */ private static $_ts = null; - private static $factory = null; + + /** + * @var ezQueryInterface[] + */ private static $instances = []; // @codeCoverageIgnoreStart @@ -67,10 +70,10 @@ public function __wakeup() * @param string $tag Store the instance for later use * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli */ - public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null) + public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null): ezQueryInterface { if (isset(self::$instances[$vendor]) && empty($setting) && empty($tag)) - return setInstance(self::$instances[$vendor]) ? self::$instances[$vendor] : false; + return self::$instances[$vendor]; if (empty($vendor) || empty($setting)) { throw new \Exception(\MISSING_CONFIGURATION); @@ -79,7 +82,7 @@ public static function initialize(?string $vendor = null, ?array $setting = null $key = $vendor; $value = \VENDOR[$key]; - if (empty($GLOBALS['ez' . $key]) || !empty($tag)) { + if (!Db::has('ez' . $key) || !empty($tag)) { $di = new DInjector(); $di->set($key, $value); $di->set('ezsql\ConfigInterface', 'ezsql\Config'); @@ -90,8 +93,9 @@ public static function initialize(?string $vendor = null, ?array $setting = null } } - setInstance($GLOBALS['ez' . $key]); - return $GLOBALS['ez' . $key]; + $db = Db::get('ez' . $key); + Db::set('global', $db); + return $db; } } diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 7de25a4f..90641b0e 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_mysqli extends ezsqlModel implements DatabaseInterface { @@ -44,9 +44,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \MYSQLI])) - $GLOBALS['ez' . \MYSQLI] = $this; - setInstance($this); + if (!Db::has('ez' . \MYSQLI)) + Db::set('ez' . \MYSQLI, $this); + Db::set('global', $this); } // __construct public function settings() diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index eec3acd1..644afbed 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_pdo extends ezsqlModel implements DatabaseInterface { @@ -47,9 +47,9 @@ public function __construct(ConfigInterface $settings = null) // Turn on track errors ini_set('track_errors', '1'); - if (empty($GLOBALS['ez' . \Pdo])) - $GLOBALS['ez' . \Pdo] = $this; - setInstance($this); + if (!Db::has('ez' . \Pdo)) + Db::set('ez' . \Pdo, $this); + Db::set('global', $this); } // __construct public function settings() diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 71f5aeb7..8ace292a 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_pgsql extends ezsqlModel implements DatabaseInterface { @@ -44,9 +44,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \PGSQL])) - $GLOBALS['ez' . \PGSQL] = $this; - setInstance($this); + if (!Db::has('ez' . \PGSQL)) + Db::set('ez' . \PGSQL, $this); + Db::set('global', $this); } // __construct public function settings() diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index f36ac7f6..1cf729f7 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_sqlite3 extends ezsqlModel implements DatabaseInterface { @@ -51,9 +51,9 @@ public function __construct(ConfigInterface $settings = null) // Turn on track errors ini_set('track_errors', '1'); - if (!isset($GLOBALS['ez' . \SQLITE3])) - $GLOBALS['ez' . \SQLITE3] = $this; - setInstance($this); + if (!Db::has('ez' . \SQLITE3)) + Db::set('ez' . \SQLITE3, $this); + Db::set('global', $this); } public function settings() diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index aca7a533..fb0f34e0 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -5,10 +5,10 @@ namespace ezsql\Database; use Exception; +use ezsql\Db; use ezsql\ezsqlModel; use ezsql\ConfigInterface; use ezsql\DatabaseInterface; -use function ezsql\functions\setInstance; class ez_sqlsrv extends ezsqlModel implements DatabaseInterface { @@ -53,9 +53,9 @@ public function __construct(ConfigInterface $settings = null) parent::__construct(); $this->database = $settings; - if (empty($GLOBALS['ez' . \SQLSRV])) - $GLOBALS['ez' . \SQLSRV] = $this; - setInstance($this); + if (!Db::has('ez' . \SQLSRV)) + Db::set('ez' . \SQLSRV, $this); + Db::set('global', $this); } public function settings() diff --git a/lib/Db.php b/lib/Db.php new file mode 100644 index 00000000..2da863e3 --- /dev/null +++ b/lib/Db.php @@ -0,0 +1,66 @@ +_position = 0; } // rewind @@ -111,7 +111,7 @@ public function current($mode = self::RESULT_AS_OBJECT) * Returns the current position in the resultset * @return int */ - public function key() + public function key(): int { return $this->_position; } // key @@ -119,7 +119,7 @@ public function key() /** * Sets the position of the resultset up by one */ - public function next() + public function next(): void { ++$this->_position; } // next @@ -128,7 +128,7 @@ public function next() * Sets position of the resultset down by one, if the position is below the * start, the position is set to the start position */ - public function previous() + public function previous(): void { --$this->_position; @@ -141,7 +141,7 @@ public function previous() * Whether the current position contains a row, or not * @return boolean */ - public function valid() + public function valid(): bool { return isset($this->_resultset[$this->_position]); } // valid @@ -159,6 +159,7 @@ public function fetch_assoc() } else { $return_val = false; } + return $return_val; } // fetch_assoc @@ -175,6 +176,7 @@ public function fetch_row() } else { $return_val = false; } + return $return_val; } // fetch_row @@ -191,6 +193,7 @@ public function fetch_object() } else { $return_val = false; } + return $return_val; } // fetch_object @@ -206,6 +209,7 @@ public function fetch_json() } else { $return_val = false; } + return $return_val; } // fetch_assoc //public function diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index cf685cc2..0208dc97 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -5,7 +5,6 @@ use ezsql\Tests\EZTestCase; use function ezsql\functions\{ - setInstance, getInstance, clearInstance, get_vendor, @@ -219,11 +218,6 @@ public function testNotBetween() $this->assertArraySubset([3 => 'data2'], notBetween('field', 'data', 'data2')); } - public function testSetInstance() - { - $this->assertFalse(setInstance()); - } - public function testSelect_into() { $this->assertFalse(select_into('field', 'data', 'data2')); From cccbe8a1318e13a0003307629fdb8535d0a4e05a Mon Sep 17 00:00:00 2001 From: techno-express Date: Mon, 25 Apr 2022 14:54:22 -0400 Subject: [PATCH 05/10] update some tests for PHP 8.1 behavior changes - update functions return type - PHP 8.1 compatible, whoever where this library return false for some access issues, 8.1 will throw errors/exceptions instead --- lib/ezFunctions.php | 38 ++++++++++++++++++------------------- tests/ezFunctionsTest.php | 5 ++++- tests/mysqli/mysqliTest.php | 20 ++++++++++++++++--- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 3ad54532..615b7aed 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -4,12 +4,12 @@ namespace ezsql\functions; +use ezsql\Db; use ezsql\ezQuery; use ezsql\ezSchema; use ezsql\Database; use ezsql\ezQueryInterface; use ezsql\DatabaseInterface; -use ezsql\Db; use ezsql\ezsqlModelInterface; if (!\function_exists('ezFunctions')) { @@ -244,7 +244,7 @@ function changingColumn(string $columnName, ...$datatype) * * @return array */ - function eq($x, $y, $and = null, ...$args) + function eq($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \EQ, $y, $and, ...$args); @@ -270,7 +270,7 @@ function eq($x, $y, $and = null, ...$args) * * @return array */ - function neq($x, $y, $and = null, ...$args) + function neq($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \NEQ, $y, $and, ...$args); @@ -287,7 +287,7 @@ function neq($x, $y, $and = null, ...$args) * * @return array */ - function ne($x, $y, $and = null, ...$args) + function ne($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \NE, $y, $and, ...$args); @@ -304,7 +304,7 @@ function ne($x, $y, $and = null, ...$args) * * @return array */ - function lt($x, $y, $and = null, ...$args) + function lt($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \LT, $y, $and, ...$args); @@ -321,7 +321,7 @@ function lt($x, $y, $and = null, ...$args) * * @return array */ - function lte($x, $y, $and = null, ...$args) + function lte($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \LTE, $y, $and, ...$args); @@ -338,7 +338,7 @@ function lte($x, $y, $and = null, ...$args) * * @return array */ - function gt($x, $y, $and = null, ...$args) + function gt($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \GT, $y, $and, ...$args); @@ -355,7 +355,7 @@ function gt($x, $y, $and = null, ...$args) * * @return array */ - function gte($x, $y, $and = null, ...$args) + function gte($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \GTE, $y, $and, ...$args); @@ -372,7 +372,7 @@ function gte($x, $y, $and = null, ...$args) * * @return array */ - function isNull($x, $y = 'null', $and = null, ...$args) + function isNull($x, $y = 'null', $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \_isNULL, $y, $and, ...$args); @@ -389,7 +389,7 @@ function isNull($x, $y = 'null', $and = null, ...$args) * * @return array */ - function isNotNull($x, $y = 'null', $and = null, ...$args) + function isNotNull($x, $y = 'null', $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \_notNULL, $y, $and, ...$args); @@ -406,7 +406,7 @@ function isNotNull($x, $y = 'null', $and = null, ...$args) * * @return array */ - function like($x, $y, $and = null, ...$args) + function like($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \_LIKE, $y, $and, ...$args); @@ -423,7 +423,7 @@ function like($x, $y, $and = null, ...$args) * * @return array */ - function notLike($x, $y, $and = null, ...$args) + function notLike($x, $y, $and = null, ...$args): array { $expression = array(); \array_push($expression, $x, \_notLIKE, $y, $and, ...$args); @@ -440,7 +440,7 @@ function notLike($x, $y, $and = null, ...$args) * * @return array */ - function in($x, $y, ...$args) + function in($x, $y, ...$args): array { $expression = array(); \array_push($expression, $x, \_IN, $y, ...$args); @@ -457,7 +457,7 @@ function in($x, $y, ...$args) * * @return array */ - function notIn($x, $y, ...$args) + function notIn($x, $y, ...$args): array { $expression = array(); \array_push($expression, $x, \_notIN, $y, ...$args); @@ -474,7 +474,7 @@ function notIn($x, $y, ...$args) * * @return array */ - function between($x, $y, $y2, ...$args) + function between($x, $y, $y2, ...$args): array { $expression = array(); \array_push($expression, $x, \_BETWEEN, $y, $y2, \_AND, ...$args); @@ -491,7 +491,7 @@ function between($x, $y, $y2, ...$args) * * @return array */ - function notBetween($x, $y, $y2, ...$args) + function notBetween($x, $y, $y2, ...$args): array { $expression = array(); \array_push($expression, $x, \_notBETWEEN, $y, $y2, \_AND, ...$args); @@ -540,7 +540,7 @@ function get_results($output = \OBJECT, $instance = null) * * @return string cleaned string */ - function clean_string(string $string) + function clean_string(string $string): string { $patterns = array( // strip out: '@]*?>.*?@si', // Strip out javascript @@ -563,7 +563,7 @@ function clean_string(string $string) * @param string $filename will be preprocess with `sanitize_path()` * @return boolean */ - function is_traversal(string $basePath, string $filename) + function is_traversal(string $basePath, string $filename): bool { if (\strpos(\urldecode($filename), '..') !== false) return true; @@ -588,7 +588,7 @@ function is_traversal(string $basePath, string $filename) * @param string $path original file/path to be sanitized. * @return string */ - function sanitize_path(string $path) + function sanitize_path(string $path): string { $file = \preg_replace("/\.[\.]+/", "", $path); $file = \preg_replace("/^[\/]+/", "", $file); diff --git a/tests/ezFunctionsTest.php b/tests/ezFunctionsTest.php index 0208dc97..d91b3acd 100644 --- a/tests/ezFunctionsTest.php +++ b/tests/ezFunctionsTest.php @@ -64,7 +64,10 @@ protected function setUp(): void public function testClean_string() { - $this->assertEquals("' help", clean_string("' help")); + if ((float) \phpversion() >= 8.1) + $this->assertEquals("' help", clean_string("' help")); + else + $this->assertEquals("' help", clean_string("' help")); } public function testSanitize_path() diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index bdae11c5..85e7e9ff 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -99,7 +99,12 @@ public function testConnect() $this->errors = array(); set_error_handler(array($this, 'errorHandler')); - $this->assertFalse($this->object->connect('no', '')); + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->connect('no', '')); + } else + $this->assertFalse($this->object->connect('no', '')); + $this->assertFalse($this->object->connect('self::TEST_DB_USER', 'self::TEST_DB_PASSWORD', ' self::TEST_DB_HOST', 'self::TEST_DB_PORT')); $result = $this->object->connect(self::TEST_DB_USER, self::TEST_DB_PASSWORD); @@ -284,8 +289,17 @@ public function testCreatingReplacing() { $this->object->quick_connect(); $this->object->prepareOff(); - $this->assertFalse($this->object->replacing([])); - $this->assertFalse($this->object->creating([])); + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->replacing([])); + } else + $this->assertFalse($this->object->replacing([])); + + if ((float) \phpversion() >= 8.1) { + $this->expectException(\mysqli_sql_exception::class); + $this->assertFalse($this->object->creating([])); + } else + $this->assertFalse($this->object->creating([])); set_table('unit_test'); $this->assertEquals( From 74df1141602b4b6148672d9373441c6d3597bd94 Mon Sep 17 00:00:00 2001 From: if3lc Date: Sat, 14 Jan 2023 20:44:22 +0300 Subject: [PATCH 06/10] Example usage fixed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8c8aaf1..8afcb5ec 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ $db = Database::initialize('****', [$dsn_path_user, $password, $database, $other use ezsql\Config; use ezsql\Database\ez_****; -$setting = new Config('****', [$dsn_path_user, $password, $database, $other_settings]); +$settings = new Config('****', [$dsn_path_user, $password, $database, $other_settings]); $db = new ez_****($settings); ``` From bc6e1d0db188cfd535061d1040d3e75d2fd90483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaz=C4=B1m=20=C3=96lmez?= Date: Wed, 30 Apr 2025 04:29:18 +0300 Subject: [PATCH 07/10] Fix Error: Uncaught TypeError: Argument 1 passed Fix in error: Fatal error: Uncaught TypeError: Argument 1 passed to ezsql\Database\ez_pdo::escape() must be of the type string, null given, called in /var/www/vendor/ezsql/ezsql/lib/ezQuery.php on line 633 and defined in /var/www/vendor/ezsql/ezsql/lib/Database/ez_pdo.php:173 Stack trace: #0 /var/www/vendor/ezsql/ezsql/lib/ezQuery.php(633): ezsql\Database\ez_pdo->escape(NULL) #1 /var/www/ajax.php(478): ezsql\ezQuery->update('restaurant', Array, Array) #2 {main} thrown in /var/www/vendor/ezsql/ezsql/lib/Database/ez_pdo.php on line 173 --- lib/ezQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 21fccb3d..4d0ff831 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -622,7 +622,7 @@ public function update(string $table = null, $keyValue, ...$whereConditions) $sql = "UPDATE $table SET "; foreach ($keyValue as $key => $val) { - if (\strtolower($val) == 'null') { + if (is_null($val) || \strtolower($val) == 'null') { $sql .= "$key = NULL, "; } elseif (\in_array(\strtolower($val), array('current_timestamp()', 'date()', 'now()'))) { $sql .= "$key = CURRENT_TIMESTAMP(), "; From 0eb24c8307fc5cd79adecebb650217c3f49c7077 Mon Sep 17 00:00:00 2001 From: Zag Date: Thu, 30 Oct 2025 11:46:47 +0000 Subject: [PATCH 08/10] Fix reference to argument in closure for params Fix reference to argument in closure for params See issue 222 --- lib/Database/ez_mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 90641b0e..0d338359 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -291,7 +291,7 @@ public function query_prepared(string $query, array $param = null) $params = []; $types = \array_reduce( $param, - function ($string, &$arg) use (&$params) { + function ($string, $arg) use (&$params) { $params[] = &$arg; if (\is_float($arg)) $string .= 'd'; From 385165f521c06edae576cd39bc517ab4073e888b Mon Sep 17 00:00:00 2001 From: dannetstudio <2724194+dannetstudio@users.noreply.github.com> Date: Thu, 2 Apr 2026 03:58:18 -0300 Subject: [PATCH 09/10] Fix PHP 8.4 implicit nullable parameter deprecations PHP 8.4 deprecated implicitly nullable parameters (typed parameters with a null default value without explicit ?Type notation). This updates all typed parameters across the library from: function foo(Type $param = null) to: function foo(?Type $param = null) Affected files: Config, ConfigInterface, DatabaseInterface, Database drivers (mysqli, pdo, pgsql, sqlite3, sqlsrv), ezFunctions, ezQuery, ezQueryInterface, ezSchema, ezsqlModel, ezsqlModelInterface. Fixes #226 --- lib/Config.php | 4 +- lib/ConfigInterface.php | 2 +- lib/Database/ez_mysqli.php | 4 +- lib/Database/ez_pdo.php | 6 +-- lib/Database/ez_pgsql.php | 4 +- lib/Database/ez_sqlite3.php | 4 +- lib/Database/ez_sqlsrv.php | 4 +- lib/DatabaseInterface.php | 2 +- lib/ezFunctions.php | 22 +++++------ lib/ezQuery.php | 76 ++++++++++++++++++------------------- lib/ezQueryInterface.php | 64 +++++++++++++++---------------- lib/ezSchema.php | 4 +- lib/ezsqlModel.php | 10 ++--- lib/ezsqlModelInterface.php | 10 ++--- 14 files changed, 108 insertions(+), 108 deletions(-) diff --git a/lib/Config.php b/lib/Config.php index 71cd75bf..af03181d 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -10,7 +10,7 @@ class Config extends ConfigAbstract implements ConfigInterface { - public function __construct(string $driver = '', array $arguments = null) + public function __construct(string $driver = '', ?array $arguments = null) { $sql = \strtolower($driver); if (!\array_key_exists($sql, \VENDOR) || empty($arguments)) { @@ -31,7 +31,7 @@ public function __construct(string $driver = '', array $arguments = null) } } - public static function initialize(string $driver = '', array $arguments = null) + public static function initialize(string $driver = '', ?array $arguments = null) { return new self($driver, $arguments); } diff --git a/lib/ConfigInterface.php b/lib/ConfigInterface.php index b3f7feee..a42b6ccc 100644 --- a/lib/ConfigInterface.php +++ b/lib/ConfigInterface.php @@ -99,5 +99,5 @@ interface ConfigInterface * for: **sqlite3** - (`filePath`, `database`) * - `filePath` // The path to open an SQLite database */ - public static function initialize(string $driver = '', array $arguments = null); + public static function initialize(string $driver = '', ?array $arguments = null); } diff --git a/lib/Database/ez_mysqli.php b/lib/Database/ez_mysqli.php index 0d338359..9ea0ff93 100644 --- a/lib/Database/ez_mysqli.php +++ b/lib/Database/ez_mysqli.php @@ -35,7 +35,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface private $database; protected $shortcutUsed = false; - public function __construct(ConfigInterface $settings = null) + public function __construct(?ConfigInterface $settings = null) { if (empty($settings)) { throw new Exception(\MISSING_CONFIGURATION); @@ -278,7 +278,7 @@ private function fetch_prepared_result(&$stmt, $query) * @param array $param * @return bool|\mysqli_result */ - public function query_prepared(string $query, array $param = null) + public function query_prepared(string $query, ?array $param = null) { $stmt = $this->dbh->prepare($query); if (!$stmt instanceof \mysqli_stmt) { diff --git a/lib/Database/ez_pdo.php b/lib/Database/ez_pdo.php index 644afbed..ab066fde 100644 --- a/lib/Database/ez_pdo.php +++ b/lib/Database/ez_pdo.php @@ -35,7 +35,7 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface */ private $database; - public function __construct(ConfigInterface $settings = null) + public function __construct(?ConfigInterface $settings = null) { if (empty($settings)) { throw new Exception(\MISSING_CONFIGURATION); @@ -235,7 +235,7 @@ public function catch_error() * @param boolean $isSelect - return \PDOStatement, if SELECT SQL statement, otherwise int * @return bool|int|\PDOStatement */ - public function query_prepared(string $query, array $param = null, $isSelect = false) + public function query_prepared(string $query, ?array $param = null, $isSelect = false) { $stmt = $this->dbh->prepare($query); $result = false; @@ -349,7 +349,7 @@ private function processResult(string $query, $result = null, bool $isSelect = f * @param array $param * @return bool|void */ - private function processQuery(string $query, array $param = null) + private function processQuery(string $query, ?array $param = null) { // Query was an insert, delete, update, replace if (\preg_match("/^(insert|delete|update|replace|drop|create)\s+/i", $query)) { diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 8ace292a..fba0efd4 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -35,7 +35,7 @@ class ez_pgsql extends ezsqlModel implements DatabaseInterface */ private $database; - public function __construct(ConfigInterface $settings = null) + public function __construct(?ConfigInterface $settings = null) { if (empty($settings)) { throw new Exception(\MISSING_CONFIGURATION); @@ -143,7 +143,7 @@ public function sysDate() * @param array $param * @return bool|mixed */ - public function query_prepared(string $query, array $param = null) + public function query_prepared(string $query, ?array $param = null) { $result = @\pg_query_params($this->dbh, $query, $param); return ($this->shortcutUsed) ? $result : $this->processQueryResult($query, $result); diff --git a/lib/Database/ez_sqlite3.php b/lib/Database/ez_sqlite3.php index 1cf729f7..86445b7b 100644 --- a/lib/Database/ez_sqlite3.php +++ b/lib/Database/ez_sqlite3.php @@ -39,7 +39,7 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface * Constructor - allow the user to perform a quick connect at the * same time as initializing the ez_sqlite3 class */ - public function __construct(ConfigInterface $settings = null) + public function __construct(?ConfigInterface $settings = null) { if (empty($settings)) { throw new Exception(\MISSING_CONFIGURATION); @@ -142,7 +142,7 @@ public function getArgType($arg) * @param array $param * @return bool \SQLite3Result */ - public function query_prepared(string $query, array $param = null) + public function query_prepared(string $query, ?array $param = null) { $stmt = $this->dbh->prepare($query); if (!$stmt instanceof \SQLite3Stmt) { diff --git a/lib/Database/ez_sqlsrv.php b/lib/Database/ez_sqlsrv.php index fb0f34e0..cb7550e2 100644 --- a/lib/Database/ez_sqlsrv.php +++ b/lib/Database/ez_sqlsrv.php @@ -44,7 +44,7 @@ class ez_sqlsrv extends ezsqlModel implements DatabaseInterface */ private $database; - public function __construct(ConfigInterface $settings = null) + public function __construct(?ConfigInterface $settings = null) { if (empty($settings)) { throw new Exception(\MISSING_CONFIGURATION); @@ -141,7 +141,7 @@ public function sysDate() * @param array $param * @return bool|mixed */ - public function query_prepared(string $query, array $param = null) + public function query_prepared(string $query, ?array $param = null) { $result = @\sqlsrv_query($this->dbh, $query, $param); if ($this->shortcutUsed) diff --git a/lib/DatabaseInterface.php b/lib/DatabaseInterface.php index ca5ae9d5..1d570f35 100644 --- a/lib/DatabaseInterface.php +++ b/lib/DatabaseInterface.php @@ -71,7 +71,7 @@ public function sysDate(); * @param array $param * @return bool|mixed */ - public function query_prepared(string $query, array $param = null); + public function query_prepared(string $query, ?array $param = null); /** * Perform SQL query and try to determine result value. diff --git a/lib/ezFunctions.php b/lib/ezFunctions.php index 615b7aed..2581ab24 100644 --- a/lib/ezFunctions.php +++ b/lib/ezFunctions.php @@ -68,7 +68,7 @@ function clearInstance(): void * @param string $instanceTag - Store the instance for later use * @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli */ - function database(string $sqlDriver = null, array $connectionSetting = null, string $instanceTag = null) + function database(?string $sqlDriver = null, ?array $connectionSetting = null, ?string $instanceTag = null) { return Database::initialize($sqlDriver, $connectionSetting, $instanceTag); } @@ -79,7 +79,7 @@ function database(string $sqlDriver = null, array $connectionSetting = null, str * @param string $getTag - An stored tag instance * @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli */ - function tagInstance(string $getTag = null) + function tagInstance(?string $getTag = null) { return database($getTag); } @@ -93,7 +93,7 @@ function tagInstance(string $getTag = null) * * @return \ezsql\Database\ez_mysqli */ - function mysqlInstance(array $databaseSetting = null, string $instanceTag = null) + function mysqlInstance(?array $databaseSetting = null, ?string $instanceTag = null) { return database(\MYSQLI, $databaseSetting, $instanceTag); } @@ -107,7 +107,7 @@ function mysqlInstance(array $databaseSetting = null, string $instanceTag = null * * @return \ezsql\Database\ez_pgsql */ - function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null) + function pgsqlInstance(?array $databaseSetting = null, ?string $instanceTag = null) { return database(\PGSQL, $databaseSetting, $instanceTag); } @@ -120,7 +120,7 @@ function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null * * @return \ezsql\Database\ez_sqlsrv */ - function mssqlInstance(array $databaseSetting = null, string $instanceTag = null) + function mssqlInstance(?array $databaseSetting = null, ?string $instanceTag = null) { return database(\MSSQL, $databaseSetting, $instanceTag); } @@ -133,7 +133,7 @@ function mssqlInstance(array $databaseSetting = null, string $instanceTag = null * * @return \ezsql\Database\ez_pdo */ - function pdoInstance(array $databaseSetting = null, string $instanceTag = null) + function pdoInstance(?array $databaseSetting = null, ?string $instanceTag = null) { return database(\Pdo, $databaseSetting, $instanceTag); } @@ -146,7 +146,7 @@ function pdoInstance(array $databaseSetting = null, string $instanceTag = null) * * @return \ezsql\Database\ez_sqlite3 */ - function sqliteInstance(array $databaseSetting = null, string $instanceTag = null) + function sqliteInstance(?array $databaseSetting = null, ?string $instanceTag = null) { return database(\SQLITE3, $databaseSetting, $instanceTag); } @@ -157,7 +157,7 @@ function sqliteInstance(array $databaseSetting = null, string $instanceTag = nul * * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` */ - function get_vendor(DatabaseInterface $instance = null): ?string + function get_vendor(?DatabaseInterface $instance = null): ?string { return ezSchema::vendor($instance); } @@ -191,7 +191,7 @@ function to_string($arrays, $separation = ','): string * * @return string|bool - SQL schema string, or false for error */ - function column(string $column = null, string $type = null, ...$arguments) + function column(?string $column = null, ?string $type = null, ...$arguments) { return ezSchema::column($column, $type, ...$arguments); } @@ -625,7 +625,7 @@ function create_certificate( string $certificateFile = 'certificate.crt', string $signingFile = 'certificate.csr', // string $caCertificate = null, - string $ssl_path = null, + ?string $ssl_path = null, array $details = ["commonName" => "localhost"] ) { if (empty($ssl_path)) { @@ -966,7 +966,7 @@ function set_prefix(string $append = '') * @return mixed bool/result - false for error * @codeCoverageIgnore */ - function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions) + function select_into(string $newTable, $fromColumns = '*', ?string $oldTable = null, ...$fromWhereConditions) { $ezQuery = getInstance(); return ($ezQuery instanceof DatabaseInterface) diff --git a/lib/ezQuery.php b/lib/ezQuery.php index 4d0ff831..07a70d38 100644 --- a/lib/ezQuery.php +++ b/lib/ezQuery.php @@ -129,11 +129,11 @@ public function having(...$conditions) } public function innerJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ) { return $this->joining( @@ -148,11 +148,11 @@ public function innerJoin( } public function leftJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ) { return $this->joining( @@ -167,11 +167,11 @@ public function leftJoin( } public function rightJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ) { return $this->joining( @@ -186,11 +186,11 @@ public function rightJoin( } public function fullJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ) { return $this->joining( @@ -232,11 +232,11 @@ public function fullJoin( */ private function joining( String $type = \_INNER, - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ) { if ( @@ -467,7 +467,7 @@ public function where(...$conditions) return ($where != '1') ? " $whereOrHaving $where " : ' '; } - public function select(string $table = null, $columnFields = '*', ...$conditions) + public function select(?string $table = null, $columnFields = '*', ...$conditions) { $getFromTable = $this->fromTable; $getSelect_result = $this->select_result; @@ -566,12 +566,12 @@ private function select_sql($table = '', $columnFields = '*', ...$conditions) return $this->select($table, $columnFields, ...$conditions); } - public function union(string $table = null, $columnFields = '*', ...$conditions) + public function union(?string $table = null, $columnFields = '*', ...$conditions) { return 'UNION ' . $this->select_sql($table, $columnFields, ...$conditions); } - public function unionAll(string $table = null, $columnFields = '*', ...$conditions) + public function unionAll(?string $table = null, $columnFields = '*', ...$conditions) { return 'UNION ALL ' . $this->select_sql($table, $columnFields, ...$conditions); } @@ -596,7 +596,7 @@ public function create_select(string $newTable, $fromColumns = '*', $oldTable = /** * @codeCoverageIgnore */ - public function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions) + public function select_into(string $newTable, $fromColumns = '*', ?string $oldTable = null, ...$fromWhereConditions) { $this->isInto = true; if (isset($oldTable)) @@ -613,7 +613,7 @@ public function select_into(string $newTable, $fromColumns = '*', string $oldTab return $this->clearPrepare(); } - public function update(string $table = null, $keyValue, ...$whereConditions) + public function update(?string $table = null, $keyValue, ...$whereConditions) { if (!\is_array($keyValue) || empty($table)) { return $this->clearPrepare(); @@ -646,7 +646,7 @@ public function update(string $table = null, $keyValue, ...$whereConditions) return $this->clearPrepare(); } - public function delete(string $table = null, ...$whereConditions) + public function delete(?string $table = null, ...$whereConditions) { if (empty($table)) { return $this->clearPrepare(); @@ -726,17 +726,17 @@ private function _query_insert_replace($table = '', $keyValue = null, $type = '' } } - public function replace(string $table = null, $keyValue) + public function replace(?string $table = null, $keyValue) { return $this->_query_insert_replace($table, $keyValue, 'REPLACE'); } - public function insert(string $table = null, $keyValue) + public function insert(?string $table = null, $keyValue) { return $this->_query_insert_replace($table, $keyValue, 'INSERT'); } - public function insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions) + public function insert_select(?string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions) { $putToTable = $this->_query_insert_replace($toTable, $toColumns, 'INSERT', false); $getFromTable = $this->select_sql($fromTable, $fromColumns, ...$conditions); @@ -750,7 +750,7 @@ public function insert_select(string $toTable = null, $toColumns = '*', $fromTab } // get_results call template - public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) + public function get_results(?string $query = null, $output = \OBJECT, bool $use_prepare = false) { return array(); } @@ -821,7 +821,7 @@ private function create_schema(array ...$columnDataOptions) return false; } - public function create(string $table = null, ...$schemas) + public function create(?string $table = null, ...$schemas) { $vendor = get_vendor(); if (empty($table) || empty($schemas) || empty($vendor)) @@ -884,7 +884,7 @@ public function create(string $table = null, ...$schemas) return false; } - public function alter(string $table = null, ...$alteringSchema) + public function alter(?string $table = null, ...$alteringSchema) { if (empty($table) || empty($alteringSchema)) return false; @@ -915,7 +915,7 @@ public function alter(string $table = null, ...$alteringSchema) return false; } - public function drop(string $table = null) + public function drop(?string $table = null) { if (empty($table)) return false; diff --git a/lib/ezQueryInterface.php b/lib/ezQueryInterface.php index 14c3f1f7..e7785164 100644 --- a/lib/ezQueryInterface.php +++ b/lib/ezQueryInterface.php @@ -114,11 +114,11 @@ public function having(...$conditions); * @return bool|string JOIN sql statement, false for error */ public function innerJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ); @@ -148,11 +148,11 @@ public function innerJoin( * @return bool|string JOIN sql statement, false for error */ public function leftJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ); @@ -182,11 +182,11 @@ public function leftJoin( * @return bool|string JOIN sql statement, false for error */ public function rightJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ); @@ -215,11 +215,11 @@ public function rightJoin( * @return bool|string JOIN sql statement, false for error */ public function fullJoin( - string $leftTable = null, - string $rightTable = null, - string $leftColumn = null, - string $rightColumn = null, - string $tableAs = null, + ?string $leftTable = null, + ?string $rightTable = null, + ?string $leftColumn = null, + ?string $rightColumn = null, + ?string $tableAs = null, $condition = \EQ ); @@ -246,7 +246,7 @@ public function fullJoin( * * @return bool|string - false for error */ - public function union(string $table = null, $columnFields = '*', ...$conditions); + public function union(?string $table = null, $columnFields = '*', ...$conditions); /** * Returns an `UNION ALL` SELECT SQL string, given the @@ -271,7 +271,7 @@ public function union(string $table = null, $columnFields = '*', ...$conditions) * * @return bool|string - false for error */ - public function unionAll(string $table = null, $columnFields = '*', ...$conditions); + public function unionAll(?string $table = null, $columnFields = '*', ...$conditions); /** * Specifies an ordering for the query results. @@ -387,7 +387,7 @@ public function where(...$conditions); * * @return mixed|object result set - see docs for more details, or false for error */ - public function select(string $table = null, $columnFields = '*', ...$conditions); + public function select(?string $table = null, $columnFields = '*', ...$conditions); /** * Preforms a `select` method call on a already preset `table name`, and optional `prefix` @@ -435,7 +435,7 @@ public function selecting($columns = '*', ...$conditions); * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) * @return mixed bool/id of inserted record, or false for error */ - public function insert(string $table = null, $keyValue); + public function insert(?string $table = null, $keyValue); /** * Preforms a `insert` method call on a already preset `table name`, and optional `prefix` @@ -504,7 +504,7 @@ public function create_select(string $newTable, $fromColumns = '*', $oldTable = *``` * @return mixed bool/result - false for error */ - public function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions); + public function select_into(string $newTable, $fromColumns = '*', ?string $oldTable = null, ...$fromWhereConditions); /** * Does an `update` query with an array, by conditional operator array @@ -531,7 +531,7 @@ public function select_into(string $newTable, $fromColumns = '*', string $oldTab *``` * @return mixed bool/results - false for error */ - public function update(string $table = null, $keyValue, ...$whereConditions); + public function update(?string $table = null, $keyValue, ...$whereConditions); /** * Preforms a `update` method call on a already preset `table name`, and optional `prefix` @@ -588,7 +588,7 @@ public function updating(array $keyValue, ...$whereConditions); *``` * @return mixed bool/results - false for error */ - public function delete(string $table = null, ...$whereConditions); + public function delete(?string $table = null, ...$whereConditions); /** * Preforms a `delete` method call on a already preset `table name`, and optional `prefix` @@ -626,7 +626,7 @@ public function deleting(...$whereConditions); * @param $keyValue - table fields, assoc array with key = value (doesn't need escaped) * @return mixed bool/id of replaced record, or false for error */ - public function replace(string $table = null, $keyValue); + public function replace(?string $table = null, $keyValue); /** * Preforms a `replace` method call on a already preset `table name`, and optional `prefix` @@ -668,7 +668,7 @@ function replacing(array $keyValue); * @return mixed bool/id of inserted record, or false for error */ public function insert_select( - string $toTable = null, + ?string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', @@ -695,7 +695,7 @@ public function insert_select( * * @return mixed results of query() call */ - public function create(string $table = null, ...$schemas); + public function create(?string $table = null, ...$schemas); /** * Preforms a `create` method call on a already preset `table name`, and optional `prefix` @@ -729,7 +729,7 @@ public function creating(...$schemas); * * @return bool|int */ - public function drop(string $table = null); + public function drop(?string $table = null); /** * Preforms a `drop` method call on a already preset `table name`, and optional `prefix` @@ -761,7 +761,7 @@ public function dropping(); * * @return mixed results of query() call */ - public function alter(string $table = null, ...$alteringSchema); + public function alter(?string $table = null, ...$alteringSchema); /** * Preforms a `alter` method call on a already preset `table name`, and optional `prefix` diff --git a/lib/ezSchema.php b/lib/ezSchema.php index 6ffafb26..06766f1b 100644 --- a/lib/ezSchema.php +++ b/lib/ezSchema.php @@ -163,7 +163,7 @@ public function __call($type, $args) * * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv` */ - public static function vendor(DatabaseInterface $db = null) + public static function vendor(?DatabaseInterface $db = null) { $type = null; $instance = empty($db) || !is_object($db) ? getInstance() : $db; @@ -202,7 +202,7 @@ public static function vendor(DatabaseInterface $db = null) * * @return string|bool - SQL schema string, or false for error */ - public static function column(string $column = null, string $type = null, ...$args) + public static function column(?string $column = null, ?string $type = null, ...$args) { $vendor = self::vendor(); if (empty($column) || empty($type) || empty($vendor)) diff --git a/lib/ezsqlModel.php b/lib/ezsqlModel.php index 897c968e..a8b84bb8 100644 --- a/lib/ezsqlModel.php +++ b/lib/ezsqlModel.php @@ -489,7 +489,7 @@ public function log_query(string $query) \array_push($this->allFuncCalls, $this->funcCall); } - public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false) + public function get_var(?string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_var(\"$query\",$x,$y)"); @@ -508,7 +508,7 @@ public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_ return (isset($values[$x]) && $values[$x] !== null) ? $values[$x] : null; } - public function get_row(string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false) + public function get_row(?string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_row(\"$query\",$output,$y)"); @@ -533,7 +533,7 @@ public function get_row(string $query = null, $output = \OBJECT, int $y = 0, boo } } - public function get_col(string $query = null, int $x = 0, bool $use_prepare = false) + public function get_col(?string $query = null, int $x = 0, bool $use_prepare = false) { $new_array = array(); @@ -553,7 +553,7 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa return $new_array; } - public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false) + public function get_results(?string $query = null, $output = \OBJECT, bool $use_prepare = false) { // Log how the function was called $this->log_query("\$db->get_results(\"$query\", $output, $use_prepare)"); @@ -601,7 +601,7 @@ public function get_col_info(string $info_type = "name", int $col_offset = -1) } } - public function create_cache(string $path = null) + public function create_cache(?string $path = null) { $cache_dir = empty($path) ? $this->cacheDir : $path; if (!\is_dir($cache_dir)) { diff --git a/lib/ezsqlModelInterface.php b/lib/ezsqlModelInterface.php index 578d3068..6c29e22e 100644 --- a/lib/ezsqlModelInterface.php +++ b/lib/ezsqlModelInterface.php @@ -267,7 +267,7 @@ public function log_query(string $query); * @param int $y - row offset * @return bool|mixed */ - public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false); + public function get_var(?string $query = null, int $x = 0, int $y = 0, bool $use_prepare = false); /** * Get one row from the database (or previously cached results) @@ -283,7 +283,7 @@ public function get_var(string $query = null, int $x = 0, int $y = 0, bool $use_ * @param int $y - row offset * @return bool|mixed */ - public function get_row(string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false); + public function get_row(?string $query = null, $output = \OBJECT, int $y = 0, bool $use_prepare = false); /** * Get one column from query (or previously cached results) based on column offset @@ -298,7 +298,7 @@ public function get_row(string $query = null, $output = \OBJECT, int $y = 0, boo * @param bool $use_prepare - has prepare statements been activated * @return bool|mixed */ - public function get_col(string $query = null, int $x = 0, bool $use_prepare = false); + public function get_col(?string $query = null, int $x = 0, bool $use_prepare = false); /** * Get multiple row result set from the database @@ -333,7 +333,7 @@ public function get_col(string $query = null, int $x = 0, bool $use_prepare = fa * @param bool $use_prepare - has prepare statements been activated * @return bool|object|array - results as objects (default) */ - public function get_results(string $query = null, $output = \OBJECT, bool $use_prepare = false); + public function get_results(?string $query = null, $output = \OBJECT, bool $use_prepare = false); /** * Get information about one or all columns such as column name or type. @@ -379,7 +379,7 @@ public function get_col_info(string $info_type = "name", int $col_offset = -1); * * @param string $path */ - public function create_cache(string $path = null); + public function create_cache(?string $path = null); /** * Store cache From 0ba7a4ea3deb4d525e48b7f1dec28346b06abc42 Mon Sep 17 00:00:00 2001 From: dannetstudio <2724194+dannetstudio@users.noreply.github.com> Date: Thu, 2 Apr 2026 04:15:07 -0300 Subject: [PATCH 10/10] Fix PHP 8.4 pg_escape_string() deprecation in ez_pgsql PHP 8.4 deprecated calling pg_escape_string() without explicitly passing the connection resource as the first argument. This updates ez_pgsql::escape() to pass $this->dbh, consistent with how ez_mysqli::escape() already passes its connection handle to mysqli_real_escape_string(). See #226 --- lib/Database/ez_pgsql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Database/ez_pgsql.php b/lib/Database/ez_pgsql.php index 8ace292a..89b3384b 100644 --- a/lib/Database/ez_pgsql.php +++ b/lib/Database/ez_pgsql.php @@ -122,7 +122,7 @@ public function connect( */ public function escape(string $str) { - return \pg_escape_string(\stripslashes($str)); + return \pg_escape_string($this->dbh, \stripslashes($str)); } // escape /**