src/DataTable.php
public function exec(array $request, $csv = false)
    {
        if ($csv) {
            $this->request['length'] = -1;
        }
        $queries = $this->generateSQLRequest($request);

        $this->addToSend('sqlQuery', $queries['data']);

        $pdo = $this->pdoLink;

        try {
            $q = $pdo->query($queries['data']);
            $this->rData = [];
            // PATCH : Annoying JOIN wich duplicate row if there is different tag
            if (isset($this->patchDuplicateRow)) {
                while ($d = $q->fetch()) {
                    $this->patchDuplicateRow($d, $this->patchDuplicateRow['pKey'], $this->patchDuplicateRow['columns']);
                }
            } else {
                $this->rData = $q ? $q->fetchAll() : [];
            }
        } catch (Exception $Exception) {
            $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['data'], $this->toSend);
        }

        if ($csv) {
            return self::sendCsv($this->rData);
        }

        if ($this->counters) {
            try {
                $q = $pdo->query($queries['recordsFiltered']);
            } catch (Exception $Exception) {
                $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsFiltered'], $this->toSend);
            }
            $recordsFiltered = $q ? $q->fetch()['count'] : 0;

            try {
                $q = $pdo->query($queries['recordsTotal']);
            } catch (Exception $Exception) {
                $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsTotal'], $this->toSend);
            }
            $recordsTotal = $q->fetch()['count'];
        } else {
            $recordsFiltered = $recordsTotal = 0;
        }

        $this->sendData($this->rData, $recordsFiltered, $recordsTotal);
    }
public function exec(array $request, $csv = false)
    {
        if ($csv) {
            $this->request['length'] = -1;
        }
        $queries = $this->generateSQLRequest($request);

        $this->addToSend('sqlQuery', $queries['data']);

        $pdo = $this->pdoLink;

        try {
            $q = $pdo->query($queries['data']);
            $this->rData = [];
            // PATCH : Annoying JOIN wich duplicate row if there is different tag
            if (isset($this->patchDuplicateRow)) {
                while ($d = $q->fetch()) {
                    $this->patchDuplicateRow($d, $this->patchDuplicateRow['pKey'], $this->patchDuplicateRow['columns']);
                }
            } else {
                $this->rData = $q ? $q->fetchAll() : [];
            }
        } catch (Exception $Exception) {
            $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['data'], $this->toSend);
        }

        if ($csv) {
            return self::sendCsv($this->rData);
        }

        if ($this->counters) {
            try {
                $q = $pdo->query($queries['recordsFiltered']);
            } catch (Exception $Exception) {
                $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsFiltered'], $this->toSend);
            }
            $recordsFiltered = $q ? $q->fetch()['count'] : 0;

            try {
                $q = $pdo->query($queries['recordsTotal']);
            } catch (Exception $Exception) {
                $this->sendFatal($pdo->errorInfo()[0].' - '.$pdo->errorInfo()[2].chr(10).$queries['recordsTotal'], $this->toSend);
            }
            $recordsTotal = $q->fetch()['count'];
        } else {
            $recordsFiltered = $recordsTotal = 0;
        }

        $this->sendData($this->rData, $recordsFiltered, $recordsTotal);
    }
public function exec ( array $ request , $ csv = false ) { if ( $ csv ) { $ this -> request [ 'length' ] = - 1 ; } $ queries = $ this -> generateSQLRequest ( $ request ) ; $ this -> addToSend ( 'sqlQuery' , $ queries [ 'data' ] ) ; $ pdo = $ this -> pdoLink ; try { $ q = $ pdo -> query ( $ queries [ 'data' ] ) ; $ this -> rData = [ ] ; // PATCH : Annoying JOIN wich duplicate row if there is different tag if ( isset ( $ this -> patchDuplicateRow ) ) { while ( $ d = $ q -> fetch ( ) ) { $ this -> patchDuplicateRow ( $ d , $ this -> patchDuplicateRow [ 'pKey' ] , $ this -> patchDuplicateRow [ 'columns' ] ) ; } } else { $ this -> rData = $ q ? $ q -> fetchAll ( ) : [ ] ; } } catch ( Exception $ Exception ) { $ this -> sendFatal ( $ pdo -> errorInfo ( ) [ 0 ] . ' - ' . $ pdo -> errorInfo ( ) [ 2 ] . chr ( 10 ) . $ queries [ 'data' ] , $ this -> toSend ) ; } if ( $ csv ) { return self :: sendCsv ( $ this -> rData ) ; } if ( $ this -> counters ) { try { $ q = $ pdo -> query ( $ queries [ 'recordsFiltered' ] ) ; } catch ( Exception $ Exception ) { $ this -> sendFatal ( $ pdo -> errorInfo ( ) [ 0 ] . ' - ' . $ pdo -> errorInfo ( ) [ 2 ] . chr ( 10 ) . $ queries [ 'recordsFiltered' ] , $ this -> toSend ) ; } $ recordsFiltered = $ q ? $ q -> fetch ( ) [ 'count' ] : 0 ; try { $ q = $ pdo -> query ( $ queries [ 'recordsTotal' ] ) ; } catch ( Exception $ Exception ) { $ this -> sendFatal ( $ pdo -> errorInfo ( ) [ 0 ] . ' - ' . $ pdo -> errorInfo ( ) [ 2 ] . chr ( 10 ) . $ queries [ 'recordsTotal' ] , $ this -> toSend ) ; } $ recordsTotal = $ q -> fetch ( ) [ 'count' ] ; } else { $ recordsFiltered = $ recordsTotal = 0 ; } $ this -> sendData ( $ this -> rData , $ recordsFiltered , $ recordsTotal ) ; }
Execute the ajax request and send the result in json

@param array $request ($_GET, $_POST...)
@param bool  $csv

@return string Exit with the json result for Datatables.js
Execute the ajax request and send the result in json