<?php
// This library is to rewrite MSYQL queries into formatted text
class query2text {
private $key_arr;
public function addline ($query,$keyword)
{
$fixed = str_ireplace(" ".$keyword,"<br> ".$keyword,$query);
return $fixed;
}
public function convert($query)
{
$key_arr = array("FROM","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","WHERE","AND","OR","ORDER","GROUP");
foreach($key_arr AS $key)
{
$query = $this->addline($query,$key);
}
$query .= "<br><br>\n";
return $query;
}
}
$query = "SELECT patients.patient_id,patients.last_name,patients.first_name,appts.*,appt_types.type,appt_types.color,appt_types.bgcolor"
. ",DATE_FORMAT(appts.start,'%m/%d/%Y') AS date"
. ",DATE_FORMAT(appts.start,'%h:%i %p') AS time"
. ",TIMEDIFF(appts.end,appts.start) AS duration"
. " FROM patients,appts,appt_types"
. " WHERE appts.cancelled IS NULL"
. " AND YEAR(appts.start)='2014'"
. " AND MONTH(appts.start)='04'"
. " AND DAY(appts.start)='1'"
. " AND patients.patient_id = appts.patient_id"
. " AND appts.type = appt_types.appt_type_id"
. " AND (appts.type='4'"
. " OR appts.type='5'"
. " OR appts.type='6'"
. " OR appts.type='7'"
. " OR appts.type='8'"
. " OR appts.type='9'"
. " OR appts.type='10'"
. " OR appts.type='11'"
. " OR appts.type='12'"
. " OR appts.type='13'"
. " OR appts.type='15'"
. " OR appts.type='16'"
. " OR appts.type='17'"
. " )"
. " ORDER BY appts.start"
. " ASC LIMIT 0,6";
$q2t = new query2text();
echo "<hr>" . $q2t->convert($query) . "<hr>\n";
<hr>SELECT patients.patient_id,patients.last_name,patients.first_name,appts.*,appt_types.type,appt_types.color,appt_types.bgcolor,DATE_FORMAT(appts.start,'%m/%d/%Y') AS date,DATE_FORMAT(appts.start,'%h:%i %p') AS time,TIMEDIFF(appts.end,appts.start) AS duration<br> FROM patients,appts,appt_types<br> WHERE appts.cancelled IS NULL<br> AND YEAR(appts.start)='2014'<br> AND MONTH(appts.start)='04'<br> AND DAY(appts.start)='1'<br> AND patients.patient_id = appts.patient_id<br> AND appts.type = appt_types.appt_type_id<br> AND (appts.type='4' OR appts.type='5' OR appts.type='6' OR appts.type='7' OR appts.type='8' OR appts.type='9' OR appts.type='10' OR appts.type='11' OR appts.type='12' OR appts.type='13' OR appts.type='15' OR appts.type='16' OR appts.type='17' )<br> ORDER BY appts.start ASC LIMIT 0,6<br><br>
<hr>
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4L5uL on line 7
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/4L5uL on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/4L5uL on line 7
Process exited with code 255.