From de91d28f6f7c758a15dd1b30b69e41ba0172ce6a Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Tue, 6 Aug 2019 02:52:47 +0100 Subject: [PATCH] [PEAR][DB] Import some new commits Patch submitted by XRevan86 [DB/pgsql.php] Change pg_exec to pg_query Encouraged by http://php.net/manual/en/function.pg-query.php and enables improved monitoring by New Relic (https://newrelic.com) [DB.php] changed count to empty for php7.2 [DB/common.php] change to array cast for php72 From: https://github.com/pear/DB/ Commits: 7d0ddaff, d04a42a5 and ea9fff4a, respectively --- extlib/DB.php | 4 ++-- extlib/DB/common.php | 9 ++++++--- extlib/DB/pgsql.php | 16 ++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/extlib/DB.php b/extlib/DB.php index e43f6091ab..18e9a287ea 100644 --- a/extlib/DB.php +++ b/extlib/DB.php @@ -660,7 +660,7 @@ class DB $parsed['dbsyntax'] = $str; } - if (!strlen($dsn)) { + if (empty($dsn)) { return $parsed; } @@ -1503,4 +1503,4 @@ class DB_row * tab-width: 4 * c-basic-offset: 4 * End: - */ \ No newline at end of file + */ diff --git a/extlib/DB/common.php b/extlib/DB/common.php index 7252ce2786..e8750972d7 100644 --- a/extlib/DB/common.php +++ b/extlib/DB/common.php @@ -1319,7 +1319,8 @@ class DB_common extends PEAR */ public function &query($query, $params = array()) { - if (sizeof($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; @@ -1361,7 +1362,8 @@ class DB_common extends PEAR { $params = (array)$params; // modifyLimitQuery() would be nice here, but it causes BC issues - if (sizeof($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; @@ -1680,7 +1682,8 @@ class DB_common extends PEAR } } - if (sizeof($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { diff --git a/extlib/DB/pgsql.php b/extlib/DB/pgsql.php index 251f9d7a89..e0387a3e22 100644 --- a/extlib/DB/pgsql.php +++ b/extlib/DB/pgsql.php @@ -332,14 +332,14 @@ class DB_pgsql extends DB_common $query = $this->modifyQuery($query); if (!$this->autocommit && $ismanip) { if ($this->transaction_opcount == 0) { - $result = @pg_exec($this->connection, 'begin;'); + $result = @pg_query($this->connection, 'begin;'); if (!$result) { return $this->pgsqlRaiseError(); } } $this->transaction_opcount++; } - $result = @pg_exec($this->connection, $query); + $result = @pg_query($this->connection, $query); if (!$result) { return $this->pgsqlRaiseError(); } @@ -737,7 +737,7 @@ class DB_pgsql extends DB_common if ($this->transaction_opcount > 0) { // (disabled) hack to shut up error messages from libpq.a //@fclose(@fopen("php://stderr", "w")); - $result = @pg_exec($this->connection, 'end;'); + $result = @pg_query($this->connection, 'end;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); @@ -757,7 +757,7 @@ class DB_pgsql extends DB_common public function rollback() { if ($this->transaction_opcount > 0) { - $result = @pg_exec($this->connection, 'abort;'); + $result = @pg_query($this->connection, 'abort;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); @@ -917,7 +917,7 @@ class DB_pgsql extends DB_common * Probably received a table name. * Create a result resource identifier. */ - $id = @pg_exec($this->connection, "SELECT * FROM $result LIMIT 0"); + $id = @pg_query($this->connection, "SELECT * FROM $result LIMIT 0"); $got_string = true; } elseif (isset($result->result)) { /* @@ -1011,7 +1011,7 @@ class DB_pgsql extends DB_common $tableWhere = "tab.relname = '$table_name'"; } - $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef + $result = @pg_query($this->connection, "SELECT f.attnotnull, f.atthasdef FROM $from WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid @@ -1022,7 +1022,7 @@ class DB_pgsql extends DB_common $flags = ($row[0] == 't') ? 'not_null ' : ''; if ($row[1] == 't') { - $result = @pg_exec($this->connection, "SELECT a.adsrc + $result = @pg_query($this->connection, "SELECT a.adsrc FROM $from, pg_attrdef a WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid AND f.attrelid = a.adrelid AND f.attname = '$field_name' @@ -1034,7 +1034,7 @@ class DB_pgsql extends DB_common } else { $flags = ''; } - $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey + $result = @pg_query($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey FROM $from, pg_index i WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid