public function read($sql)
    {
        $sql = (string)$sql;

        $conn = $this->getConnection();
        $this->Benchmark->start('sql-query');

        try {

//            if(!substr($sql, 0, 4) == 'SHOW') {
//
//                $explain = $conn->query("EXPLAIN ".$sql);
//
//                $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC);
//            }

//            $start =  microtime(TRUE);

            $result = $conn->query($sql);

//            $end =  microtime(TRUE);
//            $totalms = ($end-$start)*1000;

//            if($totalms > 1 && !empty($explainresults)) {
//
//                foreach($explainresults as $qline)
//                {
//
//                    if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all')
//                    {
//                        // table scan
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }else if($qline['rows'] > 5000) {
//
//                        // poor index
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }
//                }
//
//            }
//
//            if($totalms > 1000) {
//
//                if(!empty($explainresults)) {
//                    $pr = ArrayUtils::arrayToStr($explainresults);
//                    $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n";
//                } else {
//                    $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n";
//                }
//                error_log("[SQL]  BAD QUERY: TOOK OVER 1 SECOND\n".$email);
//
//            }




        } catch(PDOException $pe) {
            $errorMessage = $pe->getMessage();

            $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Error'               => $errorMessage,
            ));


            throw new SQLException($sql, $errorMessage, intVal($pe->getCode()));
        }

        $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Rows Returned'       => $result->rowCount(),
            ));

        unset($sql);
        unset($conn);

        return $result;
    }
public function read($sql)
    {
        $sql = (string)$sql;

        $conn = $this->getConnection();
        $this->Benchmark->start('sql-query');

        try {

//            if(!substr($sql, 0, 4) == 'SHOW') {
//
//                $explain = $conn->query("EXPLAIN ".$sql);
//
//                $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC);
//            }

//            $start =  microtime(TRUE);

            $result = $conn->query($sql);

//            $end =  microtime(TRUE);
//            $totalms = ($end-$start)*1000;

//            if($totalms > 1 && !empty($explainresults)) {
//
//                foreach($explainresults as $qline)
//                {
//
//                    if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all')
//                    {
//                        // table scan
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }else if($qline['rows'] > 5000) {
//
//                        // poor index
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }
//                }
//
//            }
//
//            if($totalms > 1000) {
//
//                if(!empty($explainresults)) {
//                    $pr = ArrayUtils::arrayToStr($explainresults);
//                    $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n";
//                } else {
//                    $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n";
//                }
//                error_log("[SQL]  BAD QUERY: TOOK OVER 1 SECOND\n".$email);
//
//            }




        } catch(PDOException $pe) {
            $errorMessage = $pe->getMessage();

            $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Error'               => $errorMessage,
            ));


            throw new SQLException($sql, $errorMessage, intVal($pe->getCode()));
        }

        $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Rows Returned'       => $result->rowCount(),
            ));

        unset($sql);
        unset($conn);

        return $result;
    }
public function read ( $ sql ) { $ sql = ( string ) $ sql ; $ conn = $ this -> getConnection ( ) ; $ this -> Benchmark -> start ( 'sql-query' ) ; try { //            if(!substr($sql, 0, 4) == 'SHOW') { // //                $explain = $conn->query("EXPLAIN ".$sql); // //                $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC); //            } //            $start =  microtime(TRUE); $ result = $ conn -> query ( $ sql ) ; //            $end =  microtime(TRUE); //            $totalms = ($end-$start)*1000; //            if($totalms > 1 && !empty($explainresults)) { // //                foreach($explainresults as $qline) //                { // //                    if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all') //                    { //                        // table scan //                        $pr = ArrayUtils::arrayToStr($explainresults); //                        error_log("[SQL]  BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // //                    }else if($qline['rows'] > 5000) { // //                        // poor index //                        $pr = ArrayUtils::arrayToStr($explainresults); //                        error_log("[SQL]  BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"); // //                    } //                } // //            } // //            if($totalms > 1000) { // //                if(!empty($explainresults)) { //                    $pr = ArrayUtils::arrayToStr($explainresults); //                    $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n"; //                } else { //                    $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n"; //                } //                error_log("[SQL]  BAD QUERY: TOOK OVER 1 SECOND\n".$email); // //            } } catch ( PDOException $ pe ) { $ errorMessage = $ pe -> getMessage ( ) ; $ this -> Logger -> debug ( array ( 'Conn' => $ this -> connDebugString , 'SQL' => $ sql , 'Execution Time (ms)' => $ this -> Benchmark -> end ( 'sql-query' ) , 'Error' => $ errorMessage , ) ) ; throw new SQLException ( $ sql , $ errorMessage , intVal ( $ pe -> getCode ( ) ) ) ; } $ this -> Logger -> debug ( array ( 'Conn' => $ this -> connDebugString , 'SQL' => $ sql , 'Execution Time (ms)' => $ this -> Benchmark -> end ( 'sql-query' ) , 'Rows Returned' => $ result -> rowCount ( ) , ) ) ; unset ( $ sql ) ; unset ( $ conn ) ; return $ result ; }
Runs the SQL query in read-only mode from the database

@param string $sql The SQL query to run

@return PDOStatement The query result
@see http://us.php.net/manual/en/pdo.query.php
Runs the SQL query in read - only mode from the database