]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBA.php
Fix: Only echo on verbose
[friendica.git] / src / Database / DBA.php
index 9debdf02a53cfb8512c1964f30d849197e0defb6..8b25f617f61195dd903de1a27995903840e417b7 100644 (file)
@@ -72,6 +72,16 @@ class DBA
                return DI::dba()->getConnection();
        }
 
+       /**
+        * Return the database driver string
+        *
+        * @return string with either "pdo" or "mysqli"
+        */
+       public static function getDriver()
+       {
+               return DI::dba()->getDriver();
+       }
+
        /**
         * Returns the MySQL server version string
         *
@@ -280,20 +290,21 @@ class DBA
        /**
         * Insert a row into a table
         *
-        * @param string|array $table               Table name or array [schema => table]
-        * @param array        $param               parameter array
-        * @param bool         $on_duplicate_update Do an update on a duplicate entry
+        * @param string|array $table          Table name or array [schema => table]
+        * @param array        $param          parameter array
+        * @param int          $duplicate_mode What to do on a duplicated entry
         *
         * @return boolean was the insert successful?
         * @throws \Exception
         */
-       public static function insert($table, $param, $on_duplicate_update = false)
+       public static function insert($table, array $param, int $duplicate_mode = Database::INSERT_DEFAULT)
        {
-               return DI::dba()->insert($table, $param, $on_duplicate_update);
+               return DI::dba()->insert($table, $param, $duplicate_mode);
        }
 
        /**
-        * Replace a row of a table
+        * Inserts a row with the provided data in the provided table.
+        * If the data corresponds to an existing row through a UNIQUE or PRIMARY index constraints, it updates the row instead.
         *
         * @param string|array $table Table name or array [schema => table]
         * @param array        $param parameter array
@@ -668,10 +679,18 @@ class DBA
         */
        public static function mergeConditions(array ...$conditions)
        {
+               if (count($conditions) == 1) {
+                       return current($conditions);
+               }
+
                $conditionStrings = [];
                $result = [];
 
                foreach ($conditions as $key => $condition) {
+                       if (!$condition) {
+                               continue;
+                       }
+
                        $condition = self::collapseCondition($condition);
 
                        $conditionStrings[] = array_shift($condition);