3 * @file src/Database/DBM.php
5 namespace Friendica\Database;
7 use Friendica\Util\DateTimeFormat;
9 require_once 'include/dba.php';
12 * @brief This class contain functions for the database management
14 * This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
19 * @brief Return a list of database processes
22 * 'list' => List of processes, separated in their different states
23 * 'amount' => Number of concurrent database processes
25 public static function processlist()
27 $r = q("SHOW PROCESSLIST");
32 foreach ($r as $process) {
33 $state = trim($process["State"]);
35 // Filter out all non blocking processes
36 if (!in_array($state, ["", "init", "statistics", "updating"])) {
43 foreach ($states as $state => $usage) {
44 if ($statelist != "") {
47 $statelist .= $state.": ".$usage;
49 return(["list" => $statelist, "amount" => $processes]);
53 * Checks if $array is a filled array with at least one entry.
55 * @param mixed $array A filled array with at least one entry
57 * @return boolean Whether $array is a filled array or an object with rows
59 public static function is_result($array)
61 // It could be a return value from an update statement
62 if (is_bool($array)) {
66 if (is_object($array)) {
67 return DBA::numRows($array) > 0;
70 return (is_array($array) && (count($array) > 0));
74 * @brief Callback function for "esc_array"
76 * @param mixed $value Array value
77 * @param string $key Array key
78 * @param boolean $add_quotation add quotation marks for string values
81 private static function esc_array_callback(&$value, $key, $add_quotation)
83 if (!$add_quotation) {
84 if (is_bool($value)) {
85 $value = ($value ? '1' : '0');
87 $value = dbesc($value);
92 if (is_bool($value)) {
93 $value = ($value ? 'true' : 'false');
94 } elseif (is_float($value) || is_integer($value)) {
95 $value = (string)$value;
97 $value = "'".dbesc($value)."'";
102 * @brief Escapes a whole array
104 * @param mixed $arr Array with values to be escaped
105 * @param boolean $add_quotation add quotation marks for string values
108 public static function esc_array(&$arr, $add_quotation = false)
110 array_walk($arr, 'self::esc_array_callback', $add_quotation);
114 * Checks Converts any date string into a SQL compatible date string
116 * @deprecated since version 3.6
117 * @param string $date a date string in any format
119 * @return string SQL style date string
121 public static function date($date = 'now')
123 return DateTimeFormat::utc($date);