db->query("use pat_lookup"); } function get_param() { $body = file_get_contents("php://input"); return json_decode($body, true); } function corss() { global $_SERVER; if (isset($_SERVER["HTTP_ORIGIN"])) { header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]); } else { header('Access-Control-Allow-Origin: */*'); } header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization'); if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") { http_response_code(200); echo json_encode("OK"); exit; } } function search() { $this->corss(); $param = $this->get_param(); $regionID = $param["regionalID"]; $search = $param["search"]; $tok = strtok($search, " "); $ft_search = ""; while ($tok != "") { $ft_search .= "+" . $tok . "* "; $tok = strtok(" "); } $sql = "select patientBizoneID,patientName,patientDOB,patientAddress,patientHP, patientEmail, patientSex, ifnull(patientNIK,'') patientNIK, patientText from patient_v2 where patientRegionalID = ? and match(patientText) against(? in boolean mode) group by patientBizoneID limit 0,20"; $qry = $this->db->query($sql, [$regionID, $ft_search]); if (!$qry) { echo json_encode([ "status" => "ERR", "message" => $this->db->error()["message"] . " | " . $this->db->last_query(), ]); exit(); } $rows = $qry->result_array(); echo json_encode(["status" => "OK", "rows" => $rows]); } }