]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into manage
authorMichael <heluecht@pirati.ca>
Mon, 30 Sep 2019 06:30:13 +0000 (06:30 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 30 Sep 2019 06:30:13 +0000 (06:30 +0000)
1  2 
src/Database/Database.php

index bf7c1c9596d993341e249c9189d656bf86848bb8,813d4e98538decbeb08e01c5d5cf9357229939cf..bf819e7e80ee35116f89425e28aaf111940d1820
@@@ -90,9 -90,12 +90,12 @@@ class Databas
        public function connect()
        {
                if (!is_null($this->connection) && $this->connected()) {
-                       return true;
+                       return $this->connected;
                }
  
+               // Reset connected state
+               $this->connected = false;
                $port       = 0;
                $serveraddr = trim($this->configCache->get('database', 'hostname'));
                $serverdata = explode(':', $serveraddr);
         */
        public function disconnect()
        {
-               if (is_null($this->connection)) {
-                       return;
+               if (!is_null($this->connection)) {
+                       switch ($this->driver) {
+                               case 'pdo':
+                                       $this->connection = null;
+                                       break;
+                               case 'mysqli':
+                                       $this->connection->close();
+                                       $this->connection = null;
+                                       break;
+                       }
                }
  
-               switch ($this->driver) {
-                       case 'pdo':
-                               $this->connection = null;
-                               break;
-                       case 'mysqli':
-                               $this->connection->close();
-                               $this->connection = null;
-                               break;
-               }
+               $this->driver    = null;
+               $this->connected = false;
        }
  
        /**
                                $connected = $this->connection->ping();
                                break;
                }
                return $connected;
        }
  
         *
         * @param string|array $table     Table name or array [schema => table]
         * @param array        $condition Array of fields for condition
 +       * @param array        $params    Array of several parameters
         *
         * @return int
         *
         * $count = DBA::count($table, $condition);
         * @throws \Exception
         */
 -      public function count($table, array $condition = [])
 +      public function count($table, array $condition = [], array $params = [])
        {
                if (empty($table)) {
                        return false;
  
                $condition_string = DBA::buildCondition($condition);
  
 -              $sql = "SELECT COUNT(*) AS `count` FROM " . $table_string . $condition_string;
 +              if (empty($params['expression'])) {
 +                      $expression = '*';
 +              } elseif (!empty($params['distinct'])) {
 +                      $expression = "DISTINCT " . DBA::quoteIdentifier($params['expression']);
 +              } else {
 +                      $expression = DBA::quoteIdentifier($params['expression']);
 +              }
 +
 +              $sql = "SELECT COUNT(" . $expression . ") AS `count` FROM " . $table_string . $condition_string;
  
                $row = $this->fetchFirst($sql, $condition);