From da6ba4416364d4e8f1bec2b16445feec434df109 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sun, 18 Jun 2017 22:16:12 -0500 Subject: [PATCH] Initialize db automatically when calling escape. Fixes #556 --- application/Controllers/Checks.php | 17 +++++++++++++++++ system/Database/MySQLi/Connection.php | 5 +++++ system/Database/Postgre/Connection.php | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/application/Controllers/Checks.php b/application/Controllers/Checks.php index 56ccfb426233..613c7960c013 100644 --- a/application/Controllers/Checks.php +++ b/application/Controllers/Checks.php @@ -3,6 +3,7 @@ use CodeIgniter\API\ResponseTrait; use CodeIgniter\Config\Services; use CodeIgniter\Controller; +use CodeIgniter\I18n\Time; use CodeIgniter\Model; use Config\Database; use Tests\Support\Models\JobModel; @@ -186,4 +187,20 @@ public function image() ddd($images); } + public function time() + { + $time = new Time(); + + echo($time); + echo '
'; + echo Time::now(); + echo '
'; + echo Time::parse('First Monday of December'); + echo '
'; + + $time = new Time('Next Monday'); + die($time); + } + + } diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index c29fbf1acf28..1df2c697426e 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -357,6 +357,11 @@ protected function _escapeString(string $str): string return $str; } + if (is_null($this->connID)) + { + $this->initialize(); + } + return $this->connID->real_escape_string($str); } diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 9b203e9716d8..436a21081a3d 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -239,6 +239,11 @@ public function escape($str) */ protected function _escapeString(string $str): string { + if (is_null($this->connID)) + { + $this->initialize(); + } + return pg_escape_string($this->connID, $str); }