prepare($sql); //Bind to query if (str_contains($whereclause, ':condition')){ $stmt->bindValue('condition', $condition, PDO::PARAM_STR); } if (!empty($criterias)){ foreach ($criterias as $key => $value){ $key_condition = ':'.$key; if (str_contains($whereclause, $key_condition)){ if ($key == 'search'){ $search_value = '%'.$value.'%'; $stmt->bindValue($key, $search_value, PDO::PARAM_STR); } else { $stmt->bindValue($key, $value, PDO::PARAM_STR); } } //CHECK IF BETWEEN STATEMENT IS SENT if (str_contains($whereclause, ':start') && str_contains($whereclause, ':end')){ //DATES ARE DELIM WITH || $dates = explode("||", $value); $stmt->bindValue('start', $dates[0], PDO::PARAM_STR); $stmt->bindValue('end', $dates[1], PDO::PARAM_STR); } } } //------------------------------------------ // Debuglog //------------------------------------------ if (debug){ $message = $date.';'.$sql.';'.$username; debuglog($message); } //Add paging details if(isset($criterias['totals']) && $criterias['totals']==''){ $stmt->execute(); $messages = $stmt->fetch(); $messages = $messages[0]; } elseif ($criterias['reporttype']){ //Excute Query $stmt->execute(); //Get results $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); } else { $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; $stmt->bindValue('page', ($current_page - 1) * $page_rows_changelog, PDO::PARAM_INT); $stmt->bindValue('num_changelog', $page_rows_changelog, PDO::PARAM_INT); //Excute Query $stmt->execute(); //Get results $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); } //------------------------------------------ //JSON_DECODE //------------------------------------------ $messages = json_encode($messages, JSON_UNESCAPED_UNICODE); //Send results echo $messages; ?>