3 * @brief This class contain functions for the database management
8 * @brief Return a list of database processes
11 * 'list' => List of processes, separated in their different states
12 * 'amount' => Number of concurrent database processes
14 public static function processlist() {
15 $r = q("SHOW PROCESSLIST");
20 foreach ($r AS $process) {
21 $state = trim($process["State"]);
23 // Filter out all non blocking processes
24 if (!in_array($state, array("", "init", "statistics", "updating"))) {
31 foreach ($states AS $state => $usage) {
34 $statelist .= $state.": ".$usage;
36 return(array("list" => $statelist, "amount" => $processes));
40 * Checks if $array is a filled array with at least one entry.
42 * @param $array mixed A filled array with at least one entry
43 * @return Whether $array is a filled array
45 public static function is_result($array) {
46 // It could be a return value from an update statement
47 if (is_bool($array)) {
51 if (is_object($array)) {
55 return (is_array($array) && count($array) > 0);
59 * @brief Callback function for "esc_array"
61 * @param mixed $value Array value
62 * @param string $key Array key
63 * @param boolean $add_quotation add quotation marks for string values
65 private static function esc_array_callback(&$value, $key, $add_quotation) {
67 if (!$add_quotation) {
68 if (is_bool($value)) {
69 $value = ($value ? '1' : '0');
71 $value = dbesc($value);
76 if (is_bool($value)) {
77 $value = ($value ? 'true' : 'false');
78 } elseif (is_float($value) OR is_integer($value)) {
79 $value = (string)$value;
81 $value = "'".dbesc($value)."'";
86 * @brief Escapes a whole array
88 * @param mixed $arr Array with values to be escaped
89 * @param boolean $add_quotation add quotation marks for string values
91 public static function esc_array(&$arr, $add_quotation = false) {
92 array_walk($arr, 'self::esc_array_callback', $add_quotation);
96 * Checks Converts any date string into a SQL compatible date string
98 * @param string $date a date string in any format
99 * @return string SQL style date string
101 public static function date($date = 'now') {
102 $timestamp = strtotime($date);
104 // Don't allow lower date strings as '0001-01-01 00:00:00'
105 if ($timestamp < -62135596800) {
106 $timestamp = -62135596800;
109 return date('Y-m-d H:i:s', $timestamp);