klenwell information services : Paste20091026

CakePhp does support bind parameters. An example model method:

    function query_bottom_count($bottom_value, $start_uts, $end_uts)
    {
        $sql = <<<XSQL
SELECT
    REPLACE( SUBSTRING_INDEX( SUBSTRING_INDEX( last_result_url,
        '://', -1 ) , '/', 1 ) , 'www.', '' ) AS domain,
    COUNT( REPLACE( SUBSTRING_INDEX( SUBSTRING_INDEX( last_result_url, '://', -1 ) ,
        '/', 1 ) , 'www.', '' ) ) AS hits
FROM queries as Query
WHERE insert_uts >= ?
AND insert_uts < ?
GROUP BY domain HAVING hits = ?;
XSQL;

        $ParamList = array($start_uts, $end_uts, $bottom_value);
        $Data = $this->query($sql, $ParamList);
        if ( !$Data ) return 0;
        return count($Data);
    }


This has been tested in 1.2.4

CategoryPastebin