3 * @brief This class contain functions for the database management
5 * This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
9 * @brief Return a list of database processes
12 * 'list' => List of processes, separated in their different states
13 * 'amount' => Number of concurrent database processes
15 public static function processlist() {
16 $r = q("SHOW PROCESSLIST");
21 foreach ($r AS $process) {
22 $state = trim($process["State"]);
24 // Filter out all non blocking processes
25 if (!in_array($state, array("", "init", "statistics", "updating"))) {
32 foreach ($states AS $state => $usage) {
35 $statelist .= $state.": ".$usage;
37 return(array("list" => $statelist, "amount" => $processes));
41 * Checks if $array is a filled array with at least one entry.
43 * @param $array mixed A filled array with at least one entry
44 * @return Whether $array is a filled array
46 public static function is_result($array) {
47 // It could be a return value from an update statement
48 if (is_bool($array)) {
52 if (is_object($array)) {
56 return (is_array($array) && count($array) > 0);
60 * @brief Callback function for "esc_array"
62 * @param mixed $value Array value
63 * @param string $key Array key
64 * @param boolean $add_quotation add quotation marks for string values
66 private static function esc_array_callback(&$value, $key, $add_quotation) {
68 if (!$add_quotation) {
69 if (is_bool($value)) {
70 $value = ($value ? '1' : '0');
72 $value = dbesc($value);
77 if (is_bool($value)) {
78 $value = ($value ? 'true' : 'false');
79 } elseif (is_float($value) || is_integer($value)) {
80 $value = (string)$value;
82 $value = "'".dbesc($value)."'";
87 * @brief Escapes a whole array
89 * @param mixed $arr Array with values to be escaped
90 * @param boolean $add_quotation add quotation marks for string values
92 public static function esc_array(&$arr, $add_quotation = false) {
93 array_walk($arr, 'self::esc_array_callback', $add_quotation);
97 * Checks Converts any date string into a SQL compatible date string
99 * @param string $date a date string in any format
100 * @return string SQL style date string
102 public static function date($date = 'now') {
103 $timestamp = strtotime($date);
105 // Don't allow lower date strings as '0001-01-01 00:00:00'
106 if ($timestamp < -62135596800) {
107 $timestamp = -62135596800;
110 return date('Y-m-d H:i:s', $timestamp);