<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
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
*
/**
* 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
/**
* 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);
}
/**
*
* @param string|array $table Table name
* @param array $conditions Field condition(s)
- * @param array $options
- * - cascade: If true we delete records in other tables that depend on the one we're deleting through
- * relations (default: true)
*
* @return boolean was the delete successful?
* @throws \Exception
* @param string|array $table Table name or array [schema => table]
* @param array $fields contains the fields that are updated
* @param array $condition condition array with the key values
- * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate)
+ * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate, false = don't update identical fields)
*
* @return boolean was the update successfull?
* @throws \Exception
* @return boolean|object
*
* Example:
- * $table = "item";
+ * $table = "post";
* $fields = array("id", "uri", "uid", "network");
*
* $condition = array("uid" => 1, "network" => 'dspr');
* @return int
*
* Example:
- * $table = "item";
+ * $table = "post";
*
* $condition = ["uid" => 1, "network" => 'dspr'];
* or:
$order_string = '';
if (isset($params['order'])) {
$order_string = " ORDER BY ";
- foreach ($params['order'] AS $fields => $order) {
+ foreach ($params['order'] as $fields => $order) {
if ($order === 'RAND()') {
$order_string .= "RAND(), ";
} elseif (!is_int($fields)) {
/**
* Fills an array with data from a query
*
- * @param object $stmt statement object
- * @param bool $do_close
+ * @param object $stmt statement object
+ * @param bool $do_close Close database connection after last row
+ * @param int $count maximum number of rows to be fetched
+ *
* @return array Data array
*/
- public static function toArray($stmt, $do_close = true)
+ public static function toArray($stmt, $do_close = true, int $count = 0)
+ {
+ return DI::dba()->toArray($stmt, $do_close, $count);
+ }
+
+ /**
+ * 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()->toArray($stmt, $do_close);
+ return DI::dba()->castFields($table, $fields);
}
/**