prepare($sql); //------------------------------------------ //Bind to query //------------------------------------------ if (!empty($criterias)){ foreach ($criterias as $key => $value){ $key_condition = ':'.$key; if (str_contains($sql, $key_condition)){ if ($key == 'p'){ //Do nothing (bug) } else { $stmt->bindValue($key, $value, PDO::PARAM_STR); } } } } //------------------------------------------ // Debuglog //------------------------------------------ if (debug){ $message = $date.';'.$sql.';'.$username; debuglog($message); } //------------------------------------------ //Execute Query //------------------------------------------ if(isset($criterias['totals']) && $criterias['totals']==''){ $stmt->execute(); $messages = $stmt->fetch(); $messages = $messages[0]; } else { //Execute Query $stmt->execute(); //Get results $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); } //------------------------------------------ //JSON_EnCODE //------------------------------------------ $messages = json_encode($messages, JSON_UNESCAPED_UNICODE); //------------------------------------------ //Send results //------------------------------------------ echo $messages; ?>