3 * @file src/Database/DBM.php
5 namespace Friendica\Database;
8 use Friendica\Util\DateTimeFormat;
10 require_once 'include/dba.php';
13 * @brief This class contain functions for the database management
15 * This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
20 * @brief Return a list of database processes
23 * 'list' => List of processes, separated in their different states
24 * 'amount' => Number of concurrent database processes
26 public static function processlist()
28 $r = q("SHOW PROCESSLIST");
33 foreach ($r as $process) {
34 $state = trim($process["State"]);
36 // Filter out all non blocking processes
37 if (!in_array($state, ["", "init", "statistics", "updating"])) {
44 foreach ($states as $state => $usage) {
45 if ($statelist != "") {
48 $statelist .= $state.": ".$usage;
50 return(["list" => $statelist, "amount" => $processes]);
54 * Checks if $array is a filled array with at least one entry.
56 * @param mixed $array A filled array with at least one entry
58 * @return boolean Whether $array is a filled array or an object with rows
60 public static function is_result($array)
62 // It could be a return value from an update statement
63 if (is_bool($array)) {
67 if (is_object($array)) {
68 return dba::num_rows($array) > 0;
71 return (is_array($array) && (count($array) > 0));
75 * @brief Callback function for "esc_array"
77 * @param mixed $value Array value
78 * @param string $key Array key
79 * @param boolean $add_quotation add quotation marks for string values
82 private static function esc_array_callback(&$value, $key, $add_quotation)
84 if (!$add_quotation) {
85 if (is_bool($value)) {
86 $value = ($value ? '1' : '0');
88 $value = dbesc($value);
93 if (is_bool($value)) {
94 $value = ($value ? 'true' : 'false');
95 } elseif (is_float($value) || is_integer($value)) {
96 $value = (string)$value;
98 $value = "'".dbesc($value)."'";
103 * @brief Escapes a whole array
105 * @param mixed $arr Array with values to be escaped
106 * @param boolean $add_quotation add quotation marks for string values
109 public static function esc_array(&$arr, $add_quotation = false)
111 array_walk($arr, 'self::esc_array_callback', $add_quotation);
115 * Checks Converts any date string into a SQL compatible date string
117 * @deprecated since version 3.6
118 * @param string $date a date string in any format
120 * @return string SQL style date string
122 public static function date($date = 'now')
124 return DateTimeFormat::utc($date);