X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FDBA.php;h=f3edf52be5f1e973f940402db42ff6cc90b5d16b;hb=f4e1acedfcd86c81403c14747ecfd3b11583506e;hp=5ebcb60e3a8d819163663932146d1c43fa61713d;hpb=a96a3679b52481ded895275096474c79d55b91c1;p=friendica.git diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 5ebcb60e3a..f3edf52be5 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -1,4 +1,23 @@ . + * + */ namespace Friendica\Database; @@ -10,8 +29,6 @@ use PDO; use PDOStatement; /** - * @class MySQL database class - * * This class is for the low level database stuff that does driver specific things. */ class DBA @@ -207,7 +224,6 @@ class DBA * * Please use DBA::selectFirst or DBA::exists whenever this is possible. * - * @brief Fetches the first row * @param string $sql SQL statement * @return array first row of query * @throws \Exception @@ -360,7 +376,9 @@ class DBA } /** - * Updates rows in the database. When $old_fields is set to an array, + * Updates rows in the database. + * + * When $old_fields is set to an array, * the system will only do an update if the fields in that array changed. * * Attention: @@ -378,7 +396,6 @@ class DBA * Only set $old_fields to a boolean value when you are sure that you will update a single row. * When you set $old_fields to "true" then $fields must contain all relevant fields! * - * @brief Updates rows * @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 @@ -631,6 +648,20 @@ class DBA /** * Returns the SQL parameter string built from the provided parameter array * + * Expected format for each key: + * + * group_by: + * - list of column names + * + * order: + * - numeric keyed column name => ASC + * - associative element with boolean value => DESC (true), ASC (false) + * - associative element with string value => 'ASC' or 'DESC' literally + * + * limit: + * - single numeric value => count + * - list with two numeric values => offset, count + * * @param array $params * @return string */ @@ -648,7 +679,11 @@ class DBA if ($order === 'RAND()') { $order_string .= "RAND(), "; } elseif (!is_int($fields)) { - $order_string .= self::quoteIdentifier($fields) . " " . ($order ? "DESC" : "ASC") . ", "; + if ($order !== 'DESC' && $order !== 'ASC') { + $order = $order ? 'DESC' : 'ASC'; + } + + $order_string .= self::quoteIdentifier($fields) . " " . $order . ", "; } else { $order_string .= self::quoteIdentifier($order) . ", "; } @@ -724,6 +759,17 @@ class DBA return DI::dba()->processlist(); } + /** + * Fetch a database variable + * + * @param string $name + * @return string content + */ + public static function getVariable(string $name) + { + return DI::dba()->getVariable($name); + } + /** * Checks if $array is a filled array with at least one entry. *