PHP Classes

Failing query type check in Query($sql)

Recommend this page to a friend!

      Ultimate MySQL  >  All threads  >  Failing query type check in Query($sql)  >  (Un) Subscribe thread alerts  
Subject:Failing query type check in Query($sql)
Summary:Checking if a query is a SELECT or INSERT in Query() Method fail
Messages:1
Author:racamiles
Date:2014-01-27 12:33:18
 

  1. Failing query type check in Query($sql)   Reply   Report abuse  
Picture of racamiles racamiles - 2014-01-27 12:33:18
In the Query() method the type of query is checked by following code:
if ( strpos(strtolower($sql), "insert") === 0){...}
else if ( strpos(strtolower($sql), "select") === 0 ){...}

For readability reasons I build my query like this:

$Sql = "
SELECT
SUM(Amount) AS Payment
FROM $Table
WHERE Ic = \"$Ic\"
AND ( PayedOn BETWEEN \"$DateFrom\" AND \"$DateTo\")
";

Naturally, the query type check fails because of the whitespaces in front of the SELECT keyword. I would suggest to TRIM the $sql in the Query() method.