]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBA.php
"id" is now post-user-id
[friendica.git] / src / Database / DBA.php
index 273c87690b45b6b61b2944f3e7cc7e6cdd94fef0..3bdcfb617a507008e94c24cbff25f08393f286b1 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
         *
@@ -173,7 +183,7 @@ class DBA
 
        /**
         * Executes a prepared statement that returns data
-        * Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
+        * Example: $r = p("SELECT * FROM `post` WHERE `guid` = ?", $guid);
         *
         * Please only use it with complicated queries.
         * For all regular queries please use DBA::select or DBA::exists
@@ -280,16 +290,16 @@ 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);
        }
 
        /**
@@ -468,7 +478,7 @@ class DBA
         * @return boolean|object
         *
         * Example:
-        * $table = "item";
+        * $table = "post";
         * $fields = array("id", "uri", "uid", "network");
         *
         * $condition = array("uid" => 1, "network" => 'dspr');
@@ -495,7 +505,7 @@ class DBA
         * @return int
         *
         * Example:
-        * $table = "item";
+        * $table = "post";
         *
         * $condition = ["uid" => 1, "network" => 'dspr'];
         * or:
@@ -669,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);
@@ -758,6 +776,18 @@ class DBA
                return DI::dba()->toArray($stmt, $do_close);
        }
 
+       /**
+        * Cast field types according to the table definition
+        *
+        * @param string $table
+        * @param array  $fields
+        * @return array casted fields
+        */
+       public static function castFields(string $table, array $fields)
+       {
+               return DI::dba()->castFields($table, $fields);
+       }
+
        /**
         * Returns the error number of the last query
         *