public function prepare($query, $fetch = null)
    {
        $query = (is_array($query)) ? trim(implode("\n", $query)) : trim($query);
        $stmt = count(static::$logs[$this->id]) + 1;
        $start = microtime(true);
        $this->prepared[$stmt]['obj'] = $this->dbPrepare($query);
        static::$logs[$this->id][$stmt] = array(
            'sql' => $query,
            'count' => 0,
            'prepared' => microtime(true) - $start,
            'executed' => 0,
        );
        $this->prepared[$stmt]['params'] = substr_count($query, '?');
        $this->prepared[$stmt]['type'] = strtoupper(strtok($query, " \r\n\t"));
        if ($this->prepared[$stmt]['type'] == 'SELECT') {
            $this->prepared[$stmt]['style'] = $this->dbStyle(strtolower((string) $fetch));
        }
        if ($this->prepared[$stmt]['obj'] === false) {
            unset($this->prepared[$stmt]);
            if ($error = $this->dbPrepareError()) {
                static::$logs[$this->id][$stmt]['errors'][] = $error;
            }

            return false;
        }

        return $stmt;
    }
public function prepare($query, $fetch = null)
    {
        $query = (is_array($query)) ? trim(implode("\n", $query)) : trim($query);
        $stmt = count(static::$logs[$this->id]) + 1;
        $start = microtime(true);
        $this->prepared[$stmt]['obj'] = $this->dbPrepare($query);
        static::$logs[$this->id][$stmt] = array(
            'sql' => $query,
            'count' => 0,
            'prepared' => microtime(true) - $start,
            'executed' => 0,
        );
        $this->prepared[$stmt]['params'] = substr_count($query, '?');
        $this->prepared[$stmt]['type'] = strtoupper(strtok($query, " \r\n\t"));
        if ($this->prepared[$stmt]['type'] == 'SELECT') {
            $this->prepared[$stmt]['style'] = $this->dbStyle(strtolower((string) $fetch));
        }
        if ($this->prepared[$stmt]['obj'] === false) {
            unset($this->prepared[$stmt]);
            if ($error = $this->dbPrepareError()) {
                static::$logs[$this->id][$stmt]['errors'][] = $error;
            }

            return false;
        }

        return $stmt;
    }
public function prepare ( $ query , $ fetch = null ) { $ query = ( is_array ( $ query ) ) ? trim ( implode ( "\n" , $ query ) ) : trim ( $ query ) ; $ stmt = count ( static :: $ logs [ $ this -> id ] ) + 1 ; $ start = microtime ( true ) ; $ this -> prepared [ $ stmt ] [ 'obj' ] = $ this -> dbPrepare ( $ query ) ; static :: $ logs [ $ this -> id ] [ $ stmt ] = array ( 'sql' => $ query , 'count' => 0 , 'prepared' => microtime ( true ) - $ start , 'executed' => 0 , ) ; $ this -> prepared [ $ stmt ] [ 'params' ] = substr_count ( $ query , '?' ) ; $ this -> prepared [ $ stmt ] [ 'type' ] = strtoupper ( strtok ( $ query , " \r\n\t" ) ) ; if ( $ this -> prepared [ $ stmt ] [ 'type' ] == 'SELECT' ) { $ this -> prepared [ $ stmt ] [ 'style' ] = $ this -> dbStyle ( strtolower ( ( string ) $ fetch ) ) ; } if ( $ this -> prepared [ $ stmt ] [ 'obj' ] === false ) { unset ( $ this -> prepared [ $ stmt ] ) ; if ( $ error = $ this -> dbPrepareError ( ) ) { static :: $ logs [ $ this -> id ] [ $ stmt ] [ 'errors' ] [ ] = $ error ; } return false ; } return $ stmt ; }
Prepare a query to be executed.

@param string|array $query An SQL statement.
@param string       $fetch How you would like the SELECT rows returned.  Either '**obj**', '**assoc**', '**named**', '**both**', or '**num**' (the default).

@return bool|int Either ``false`` if there was an error, or a ``$stmt`` id that can be``$db->execute()``d or ``$db->fetch()``ed.  Don't forget to ``$db->close($stmt)``.
Prepare a query to be executed .