Provides a shortcut to get Database related objects for making queries.
You pass the same parameters to these functions as you pass to the objects they return.
- package
- Kohana/Database
- category
- Base
- author
- Kohana Team
- copyright
- © 2009 Kohana Team
- license
- http://kohanaphp.com/license
Class declared in MODPATH/database/classes/db.php on line 3.
public static delete( [ string $table = NULL ] )
(defined in Kohana_DB)
link to this
Parameters
-
string
$table
= NULL - Table to delete from
Return Values
Database_Query_Builder_Delete
Source Code
public static function delete ( $table = NULL)
{
return new Database_Query_Builder_Delete( $table );
}
|
public static expr( string $string [, array $parameters = array(0) ] )
(defined in Kohana_DB)
link to this
Create a new Database_Expression which is not escaped. An expression
is the only way to use SQL functions within query builders.
$expression = DB::expr( 'COUNT(users.id)' );
$query = DB::update( 'users' )->set( array ( 'login_count' => DB::expr( 'login_count + 1' )))->where( 'id' , '=' , $id );
$users = ORM::factory( 'user' )->where(DB::expr( "BINARY `hash`" ), '=' , $hash )->find();
|
Parameters
-
string
$string
required - Expression
-
array
$parameters
= array(0) - Parameters
Return Values
Source Code
public static function expr( $string , $parameters = array ())
{
return new Database_Expression( $string , $parameters );
}
|
public static insert( [ string $table = NULL , array $columns = NULL ] )
(defined in Kohana_DB)
link to this
Parameters
-
string
$table
= NULL - Table to insert into
-
array
$columns
= NULL - List of column names or array($column, $alias) or object
Return Values
Database_Query_Builder_Insert
Source Code
public static function insert( $table = NULL, array $columns = NULL)
{
return new Database_Query_Builder_Insert( $table , $columns );
}
|
public static query( integer $type , string $sql )
(defined in Kohana_DB)
link to this
Create a new Database_Query of the given type.
$query = DB::query(Database::SELECT, 'SELECT * FROM users' );
$query = DB::query(Database:: DELETE , 'DELETE FROM users WHERE id = 5' );
|
Specifying the type changes the returned result. When using
Database::SELECT
, a Database_Query_Result will be returned.
Database::INSERT
queries will return the insert id and number of rows.
For all other queries, the number of affected rows is returned.
Parameters
-
integer
$type
required - Type: Database::SELECT, Database::UPDATE, etc
-
string
$sql
required - SQL statement
Return Values
Source Code
public static function query( $type , $sql )
{
return new Database_Query( $type , $sql );
}
|
public static select( [ mixed $columns = NULL ] )
(defined in Kohana_DB)
link to this
Create a new Database_Query_Builder_Select. Each argument will be
treated as a column. To generate a foo AS bar
alias, use an array.
$query = DB::select( 'id' , 'username' );
$query = DB::select( array ( 'id' , 'user_id' ));
|
Parameters
-
mixed
$columns
= NULL - Column name or array($column, $alias) or object
Return Values
Database_Query_Builder_Select
Source Code
public static function select( $columns = NULL)
{
return new Database_Query_Builder_Select(func_get_args());
}
|
public static select_array( [ array $columns = NULL ] )
(defined in Kohana_DB)
link to this
Parameters
-
array
$columns
= NULL - Columns to select
Return Values
Database_Query_Builder_Select
Source Code
public static function select_array( array $columns = NULL)
{
return new Database_Query_Builder_Select( $columns );
}
|
public static update( [ string $table = NULL ] )
(defined in Kohana_DB)
link to this
Parameters
-
string
$table
= NULL - Table to update
Return Values
Database_Query_Builder_Update
Source Code
public static function update( $table = NULL)
{
return new Database_Query_Builder_Update( $table );
}
|