Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Added escapeLiteral method
givanz8b0c34ec48d0
diff --git a/system/db/mysqli.php b/system/db/mysqli.phpindex 8d18528..664b3c6 100755--- a/system/db/mysqli.php+++ b/system/db/mysqli.php@@ -176,7 +176,7 @@ class Mysqli extends DBDriver {$columns = [];while ($row = $result->fetch_assoc()) {- $columns[] = $row;+ $columns[$row['name']] = $row;}/* free result set */@@ -217,6 +217,10 @@ class Mysqli extends DBDriver {}public function query($sql) {+ if (LOG_SQL_QUERIES) {+ error_log($sql);+ }+$result = self :: $link->query($sql);if ($result) {@@ -250,28 +254,52 @@ class Mysqli extends DBDriver {return $string;}+ public function escapeLiteral($string) {+ return $this->escape($string);+ }+public function sqlLimit($start, $limit) {return "LIMIT $start, $limit";}public function fetchArray($stmt) {- $result = $stmt->get_result();+ $data = [];+ $statement = (get_class($stmt) === 'mysqli_stmt');++ if ($statement) {+ $this->store_result();+ $result = $stmt->get_result();+ } else {+ $result = $stmt;+ }if ($result) {- return $result->fetch_array(MYSQLI_ASSOC);+ $data = $result->fetch_array(MYSQLI_ASSOC);++ if ($statement && $stmt->more_results()) {+ $stmt->next_result();+ }}- return [];+ return $data;}public function fetchAll($stmt) {- $result = $stmt->get_result();+ $data = [];+ $statement = (get_class($stmt) === 'mysqli_stmt');++ if ($statement) {+ $this->store_result();+ $result = $stmt->get_result();+ } else {+ $result = $stmt;+ }if ($result) {- return $result->fetch_all(MYSQLI_ASSOC);+ $data = $result->fetch_all(MYSQLI_ASSOC);}- return [];+ return $data;}public function store_result() {diff --git a/system/db/pgsql.php b/system/db/pgsql.phpindex 3e7841d..45faa6a 100755--- a/system/db/pgsql.php+++ b/system/db/pgsql.php@@ -109,7 +109,7 @@ class Pgsql extends DBDriver {$columns = [];while ($row = pg_fetch_assoc($result)) {- $columns[] = $row;+ $columns[$row['name']] = $row;}/* free result set */@@ -153,6 +153,18 @@ class Pgsql extends DBDriver {return $string;}+ public function escapeLiteral($string) {+ if (is_string($string)) {+ return pg_escape_literal(self :: $link, $string);+ }++ if (is_null($string)) {+ return 'null';+ }++ return $string;+ }+public function sqlLimit($start, $limit) {return "LIMIT $limit OFFSET $start";}@@ -190,9 +202,17 @@ class Pgsql extends DBDriver {try {if ($parameters) {- $this->last_res = @pg_query_params(self :: $link, $sql, $parameters);+ if (LOG_SQL_QUERIES) {+ error_log($this->debugSql($sql, $parameters));+ }++ $this->last_res = $result = @pg_query_params(self :: $link, $sql, $parameters);} else {- $this->last_res = @pg_query(self :: $link, $sql);+ if (LOG_SQL_QUERIES) {+ error_log($sql);+ }++ $this->last_res = $result = @pg_query(self :: $link, $sql);}if ($this->last_res == false) {@@ -289,7 +309,7 @@ class Pgsql extends DBDriver {list($parameters, $types) = $this->paramsToQmark($sql, $params, $paramTypes, '$');- if (DEBUG) {+ if (LOG_SQL_QUERIES) {error_log($this->debugSql($origSql, $params, $paramTypes));}@@ -306,8 +326,11 @@ class Pgsql extends DBDriver {}if ($this->last_res == false) {- error_log('pgsql error: ' . pg_result_error($this->last_res) . pg_last_error(self :: $link));- error_log($this->debugSql($origSql, $params, $paramTypes));+ $errorMessage = pg_last_error(self :: $link);+ //error_log('pgsql error: ' . pg_last_error(self :: $link));+ $errorMessage .= $this->debugSql($origSql, $params, $paramTypes);++ throw new \Exception($errorMessage);}return $this->last_res;diff --git a/system/db/sqlite.php b/system/db/sqlite.phpindex 5315181..1f172c9 100755--- a/system/db/sqlite.php+++ b/system/db/sqlite.php@@ -102,7 +102,7 @@ class Sqlite extends DBDriver {$columns = [];while ($row = $result->fetchArray(SQLITE3_ASSOC)) {- $columns[] = $row;+ $columns[$row['name']] = $row;}/* free result set */@@ -149,6 +149,10 @@ class Sqlite extends DBDriver {return $string;}+ public function escapeLiteral($string) {+ return $this->escape($string);+ }+public function sqlLimit($start, $limit) {return "LIMIT $start, $limit";}@@ -191,6 +195,10 @@ class Sqlite extends DBDriver {try {$result = self :: $link->query($sql);+ if (LOG_SQL_QUERIES) {+ error_log($sql);+ }+if ($result) {$this->affected_rows = self :: $link->changes();$this->insert_id = self :: $link->lastInsertRowID();@@ -209,15 +217,40 @@ class Sqlite extends DBDriver {}public function multi_query($sql) {- $result = self :: $link->query($sql);+ $results = [];- if ($result) {- $this->affected_rows = self :: $link->changes();- $this->insert_id = self :: $link->lastInsertRowID();- $this->num_rows = $result->numColumns() && $result->columnType(0) != SQLITE3_NULL;+ $queries = preg_split('/;\n/', $sql);++ foreach ($queries as $query) {+ if (empty(trim($query))) {+ continue;+ }++ if (LOG_SQL_QUERIES) {+ error_log($sql);+ }++ try {+ $result = self :: $link->query("$query;");++ if ($result) {+ $this->affected_rows = self :: $link->changes();+ $this->insert_id = self :: $link->lastInsertRowID();+ $this->num_rows = $result->numColumns() && $result->columnType(0) != SQLITE3_NULL;+ //$result->finalize();+ } else {+ throw new \Exception($this->error(), $this->errorCode());+ }++ $results[] = $result;+ } catch (\Exception $e) {+ $message = $e->getMessage() . "\n$query\n";++ throw new \Exception($message, $e->getCode());+ }}- return $result;+ return $results;}public function close() {