src/Services/Database.php
protected function perform($statement, array $bindings = [], $class = null)
    {
        $this->connect();

        if (empty($bindings)) {
            try {
                if (($sth = $this->pdo->query($statement)) === false) {
                    throw new PDOException('Execute SQL query failed!');
                }
            }
            catch (PDOException $e) {
                throw new QueryException($statement, $bindings, $statement, $e);
            }
        }
        else {
            try {
                $sth = $this->pdo->prepare($statement);

                foreach ($bindings as $key => $value) {
                    if (is_int($key)) {
                        $key += 1;
                    }

                    if ($value instanceof DateTimeInterface) {
                        $value = $value->format($this->dateFormat);
                    }
                    else if ($value === false) { // das macht Eloquent!
                        $value = 0;
                    }

                    $type = is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR;
                    $sth->bindValue($key, $value, $type);
                }

                if ($sth->execute() === false) {
                    throw new PDOException('Execute SQL query failed!');
                }
            }
            catch (PDOException $e) {
                throw new QueryException($statement, $bindings, $this->dump($statement, $bindings, true), $e);
            }
        }

        if ($class !== null) {
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(PDO::FETCH_CLASS, $class);
        }

        return $sth;
    }
protected function perform($statement, array $bindings = [], $class = null)
    {
        $this->connect();

        if (empty($bindings)) {
            try {
                if (($sth = $this->pdo->query($statement)) === false) {
                    throw new PDOException('Execute SQL query failed!');
                }
            }
            catch (PDOException $e) {
                throw new QueryException($statement, $bindings, $statement, $e);
            }
        }
        else {
            try {
                $sth = $this->pdo->prepare($statement);

                foreach ($bindings as $key => $value) {
                    if (is_int($key)) {
                        $key += 1;
                    }

                    if ($value instanceof DateTimeInterface) {
                        $value = $value->format($this->dateFormat);
                    }
                    else if ($value === false) { // das macht Eloquent!
                        $value = 0;
                    }

                    $type = is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR;
                    $sth->bindValue($key, $value, $type);
                }

                if ($sth->execute() === false) {
                    throw new PDOException('Execute SQL query failed!');
                }
            }
            catch (PDOException $e) {
                throw new QueryException($statement, $bindings, $this->dump($statement, $bindings, true), $e);
            }
        }

        if ($class !== null) {
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(PDO::FETCH_CLASS, $class);
        }

        return $sth;
    }
protected function perform ( $ statement , array $ bindings = [ ] , $ class = null ) { $ this -> connect ( ) ; if ( empty ( $ bindings ) ) { try { if ( ( $ sth = $ this -> pdo -> query ( $ statement ) ) === false ) { throw new PDOException ( 'Execute SQL query failed!' ) ; } } catch ( PDOException $ e ) { throw new QueryException ( $ statement , $ bindings , $ statement , $ e ) ; } } else { try { $ sth = $ this -> pdo -> prepare ( $ statement ) ; foreach ( $ bindings as $ key => $ value ) { if ( is_int ( $ key ) ) { $ key += 1 ; } if ( $ value instanceof DateTimeInterface ) { $ value = $ value -> format ( $ this -> dateFormat ) ; } else if ( $ value === false ) { // das macht Eloquent! $ value = 0 ; } $ type = is_int ( $ value ) ? PDO :: PARAM_INT : PDO :: PARAM_STR ; $ sth -> bindValue ( $ key , $ value , $ type ) ; } if ( $ sth -> execute ( ) === false ) { throw new PDOException ( 'Execute SQL query failed!' ) ; } } catch ( PDOException $ e ) { throw new QueryException ( $ statement , $ bindings , $ this -> dump ( $ statement , $ bindings , true ) , $ e ) ; } } if ( $ class !== null ) { /** @noinspection PhpMethodParametersCountMismatchInspection */ $ sth -> setFetchMode ( PDO :: FETCH_CLASS , $ class ) ; } return $ sth ; }
Performs a sql statement with bound values and returns the resulting PDOStatement.

* @see http://php.net/manual/en/pdo.prepare.php

@param string $statement The SQL statement to perform.
@param array $bindings Values to bind to the statement
@param string|null $class Name of the class where the data are mapped to
@return PDOStatement
@throws Exception
Performs a sql statement with bound values and returns the resulting PDOStatement .