Methods

Creates a new SQL query of the specified type.

__construct(string $sql, integer $type) 

Parameters

$sql

string

query string

$type

integer

query type: DB::SELECT, DB::INSERT, etc

Return the SQL query string.

__toString() : string

Returns

string

Returns results as associative arrays

as_assoc() : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Returns

Returns results as objects

as_object(mixed $class) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$class

mixed

classname or true for stdClass

Returns

Bind a variable to a parameter in the query.

bind(string $param, mixed $var) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$param

string

parameter key to replace

$var

mixed

variable to use

Returns

Enables the query to be cached for a specified amount of time.

cached(integer $lifetime, string $cache_key, boolean $cache_all) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$lifetime

integer

number of seconds to cache or null for default

$cache_key

string

name of the cache key to be used or null for default

$cache_all

boolean

if true, cache all results, even empty ones

Returns

Compile the SQL query and return it.

compile(mixed $db) : string

Replaces any parameters with their given values.

Parameters

$db

mixed

Database instance or instance name

Returns

string

Execute the current query on the given database.

execute(mixed $db) : object: mixed: integer

Parameters

$db

mixed

Database instance or name of instance

Returns

objectDatabase_Result for SELECT queries
mixedthe insert id for INSERT queries
integernumber of affected rows for all other queries

Set the value of a parameter in the query.

param(string $param, mixed $value) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$param

string

parameter key to replace

$value

mixed

value to use

Returns

Add multiple parameters to the query.

parameters(array $params) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$params

array

list of parameters

Returns

Set a DB connection to use when compiling the SQL

set_connection(mixed $db) : \Fuel\Core\Database_Query

fluent This method is part of a fluent interface and will return the same instance

Parameters

$db

mixed

Returns

Get the type of the query.

type() : integer

Returns

integer

 Properties

 

<p>Return results as associative arrays or objects</p>

$_as_object : bool

 

<p>Cache all results</p>

$_cache_all : boolean

 

<p>Cache key</p>

$_cache_key : string

 

<p>Connection to use when compiling the SQL</p>

$_connection : \Fuel\Core\Database_Connection

 

<p>Cache lifetime</p>

$_lifetime : int

 

<p>Quoted query parameters</p>

$_parameters : array

 

<p>SQL statement</p>

$_sql : string

 

<p>Query type</p>

$_type : int