JREAM
10/6/2013 - 6:16 PM

Example PDO with Extra params

Example PDO with Extra params

// Example with Extra:
Usage: $this->select('id', null, 'ORDER BY anything LIMIT 2');

public function select($columns, $where = null, $extra = null) {
        $this->_isTableSet();
        
        if (is_array($columns)) {
            $columns = implode(',', $columns);
        }
        
        // Build the WHERE Statement
        $where_stmt = $this->_whereBuilder($where);
        if (!is_array($where)) {
            $where = ['primary_key' => $where];
        }
        
        if ($extra != null) {
            $extra_str = $extra
        }

        // Run the Query
        $stmt = $this->prepare("SELECT $columns FROM `{$this->table}` $where_stmt $extra");
        $stmt->execute($where);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }