Having a tough time with this one query. It states "Hacking Attempt...". I change the variables and get other errors. A straight query gets a hacking attempt. What must be done to this query to get it accepted. the query works in mySQL.
function GetTopicVisitsDownloadsPerHour($selecteddate)
{
global $smcFunc,$context;
$query = "Select a.Segment as Segment, Count(a.Segment) as Downloads from
(Select hour(`updated`) as Segment FROM {db_prefix}log_downloads
where updated = {date:selected})) `a`
group by Segment";
$segment_result = $smcFunc['db_query']('',
$query,
array('selected' => $selecteddate
)
);
Original Query
function GetTopicVisitsDownloadsPerHour($selecteddate)
{
global $smcFunc,$context;
$query = "Select a.Segment as Segment, Count(a.Segment) as Downloads from
(Select hour(`updated`) as Segment FROM {db_prefix}log_downloads
where (cast(`updated` as date) = '" . $selecteddate . "')) `a`
group by Segment";
$smcFunc doesn't allow sub SELECTs (unless (maybe, at the moment I don't remember the details) you disable the security checks).
How would one disable the security checks for one call? I did not see anything on the $smcFunc page about this.
$disableQueryCheckBack = $modSettings['disableQueryCheck'];
$modSettings['disableQueryCheck'] = true;
// do query here
$modSettings['disableQueryCheck'] = $disableQueryCheckBack;
Line 301 of Subs-Db-mysql.php is where the checks start. The sub-query check is on lines 345-347.
Thanks Sorck. That worked.
Thanks emanuele for your help.