libraries/Database – Kohana API 2.3 Documentation

system/libraries/Database.php

Class: Database_Core

class Database_Core

Provides database access in a platform agnostic way, using simple query building blocks.


Methods

Database_Core :: instance

public static function instance

Returns a singleton instance of Database.

Parameters:

mixed name
(string default) configuration array or DSN
config
(NULL)

Return: Database_Core


Database_Core :: instance_name

public static function instance_name

Returns the name of a given database instance.

Parameters:

Database db
instance of Database

Return: string


Database_Core -> __construct

public function __construct

Sets up the database configuration, loads the Database_Driver.

Parameters:

config
(array)

Throws: Kohana_Database_Exception


Database_Core -> connect

public function connect

Simple connect method to get the database queries up and running.

Return: void


Database_Core -> query

public function query

Runs a query into the driver and returns the result.

Parameters:

string sql
(string ) SQL query to execute

Return: Database_Result


Database_Core -> select

public function select

Selects the column names for a database query.

Parameters:

string sql
(string *) string or array of column names to select

Return: Database_Core This Database object.


Database_Core -> from

public function from

Selects the from table(s) for a database query.

Parameters:

string sql
string or array of tables to select

Return: Database_Core This Database object.


Database_Core -> join

public function join

Generates the JOIN portion of the query.

Parameters:

string table
table name
string or array key
where key or array of key => value pairs
string value
(NULL) where value
string type
(string ) type of join

Return: Database_Core This Database object.


Database_Core -> where

public function where

Selects the where(s) for a database query.

Parameters:

string or array key
key name or array of key => value pairs
string value
(NULL) value to match with key
boolean quote
(TRUE) disable quoting of WHERE clause

Return: Database_Core This Database object.


Database_Core -> orwhere

public function orwhere

Selects the or where(s) for a database query.

Parameters:

string or array key
key name or array of key => value pairs
string value
(NULL) value to match with key
boolean quote
(TRUE) disable quoting of WHERE clause

Return: Database_Core This Database object.


Database_Core -> like

public function like

Selects the like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field
boolean auto
(TRUE) automatically add starting and ending wildcards

Return: Database_Core This Database object.


Database_Core -> orlike

public function orlike

Selects the or like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field
boolean auto
(TRUE) automatically add starting and ending wildcards

Return: Database_Core This Database object.


Database_Core -> notlike

public function notlike

Selects the not like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field
boolean auto
(TRUE) automatically add starting and ending wildcards

Return: Database_Core This Database object.


Database_Core -> ornotlike

public function ornotlike

Selects the or not like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field
auto
(TRUE)

Return: Database_Core This Database object.


Database_Core -> regex

public function regex

Selects the like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field

Return: Database_Core This Database object.


Database_Core -> orregex

public function orregex

Selects the or like(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) like value to match with field

Return: Database_Core This Database object.


Database_Core -> notregex

public function notregex

Selects the not regex(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) regex value to match with field

Return: Database_Core This Database object.


Database_Core -> ornotregex

public function ornotregex

Selects the or not regex(s) for a database query.

Parameters:

string or array field
field name or array of field => match pairs
string match
(string ) regex value to match with field

Return: Database_Core This Database object.


Database_Core -> groupby

public function groupby

Chooses the column to group by in a select query.

Parameters:

string by
column name to group by

Return: Database_Core This Database object.


Database_Core -> having

public function having

Selects the having(s) for a database query.

Parameters:

string or array key
key name or array of key => value pairs
string value
(string ) value to match with key
boolean quote
(TRUE) disable quoting of WHERE clause

Return: Database_Core This Database object.


Database_Core -> orhaving

public function orhaving

Selects the or having(s) for a database query.

Parameters:

string or array key
key name or array of key => value pairs
string value
(string ) value to match with key
boolean quote
(TRUE) disable quoting of WHERE clause

Return: Database_Core This Database object.


Database_Core -> orderby

public function orderby

Chooses which column(s) to order the select query by.

Parameters:

string or array orderby
column(s) to order on, can be an array, single column, or comma seperated list of columns
string direction
(NULL) direction of the order

Return: Database_Core This Database object.


Database_Core -> limit

public function limit

Selects the limit section of a query.

Parameters:

integer limit
number of rows to limit result to
integer offset
(NULL) offset in result to start returning rows from

Return: Database_Core This Database object.


Database_Core -> offset

public function offset

Sets the offset portion of a query.

Parameters:

integer value
offset value

Return: Database_Core This Database object.


Database_Core -> set

public function set

Allows key/value pairs to be set for inserting or updating.

Parameters:

string or array key
key name or array of key => value pairs
string value
(string ) value to match with key

Return: Database_Core This Database object.


Database_Core -> get

public function get

Compiles the select statement based on the other functions called and runs the query.

Parameters:

string table
(string ) table name
string limit
(NULL) limit clause
string offset
(NULL) offset clause

Return: Database_Result


Database_Core -> getwhere

public function getwhere

Compiles the select statement based on the other functions called and runs the query.

Parameters:

string table
(string ) table name
array where
(NULL) where clause
string limit
(NULL) limit clause
string offset
(NULL) offset clause

Return: Database_Core This Database object.


Database_Core -> compile

public function compile

Compiles the select statement based on the other functions called and returns the query string.

Parameters:

string table
(string ) table name
string limit
(NULL) limit clause
string offset
(NULL) offset clause

Return: string sql string


Database_Core -> insert

public function insert

Compiles an insert string and runs the query.

Parameters:

string table
(string ) table name
array set
(NULL) array of key/value pairs to insert

Return: Database_Result Query result


Database_Core -> in

public function in

Adds an "IN" condition to the where clause

Parameters:

string field
Name of the column being examined
mixed values
An array or string to match against
bool not
(FALSE) Generate a NOT IN clause instead

Return: Database_Core This Database object.


Database_Core -> notin

public function notin

Adds a "NOT IN" condition to the where clause

Parameters:

string field
Name of the column being examined
mixed values
An array or string to match against

Return: Database_Core This Database object.


Database_Core -> merge

public function merge

Compiles a merge string and runs the query.

Parameters:

string table
(string ) table name
array set
(NULL) array of key/value pairs to merge

Return: Database_Result Query result


Database_Core -> update

public function update

Compiles an update string and runs the query.

Parameters:

string table
(string ) table name
array set
(NULL) associative array of update values
array where
(NULL) where clause

Return: Database_Result Query result


Database_Core -> delete

public function delete

Compiles a delete string and runs the query.

Parameters:

string table
(string ) table name
array where
(NULL) where clause

Return: Database_Result Query result


Database_Core -> last_query

public function last_query

Returns the last query run.

Return: string SQL


Database_Core -> count_records

public function count_records

Count query records.

Parameters:

string table
(FALSE) table name
array where
(NULL) where clause

Return: integer


Database_Core -> reset_select

protected function reset_select

Resets all private select variables.

Return: void


Database_Core -> reset_write

protected function reset_write

Resets all private insert and update variables.

Return: void


Database_Core -> list_tables

public function list_tables

Lists all the tables in the current database.

Return: array


Database_Core -> table_exists

public function table_exists

See if a table exists in the database.

Parameters:

string table_name
table name

Return: boolean


Database_Core -> compile_binds

public function compile_binds

Combine a SQL statement with the bind values. Used for safe queries.

Parameters:

string sql
query to bind to the values
array binds
array of values to bind to the query

Return: string


Database_Core -> field_data

public function field_data

Get the field data for a database table, along with the field's attributes.

Parameters:

string table
(string ) table name

Return: array


Database_Core -> list_fields

public function list_fields

Get the field data for a database table, along with the field's attributes.

Parameters:

string table
(string ) table name

Return: array


Database_Core -> escape

public function escape

Escapes a value for a query.

Parameters:

mixed value
value to escape

Return: string


Database_Core -> escape_str

public function escape_str

Escapes a string for a query.

Parameters:

string str
string to escape

Return: string


Database_Core -> escape_table

public function escape_table

Escapes a table name for a query.

Parameters:

string table
string to escape

Return: string


Database_Core -> escape_column

public function escape_column

Escapes a column name for a query.

Parameters:

string table
string to escape

Return: string


Database_Core -> table_prefix

public function table_prefix

Returns table prefix of current configuration.

Return: string


Database_Core -> clear_cache

public function clear_cache

Clears the query cache.

Parameters:

string or TRUE sql
(NULL) clear cache by SQL statement or TRUE for last query

Return: Database_Core This Database object.


Database_Core -> stmt_prepare

public function stmt_prepare

Create a prepared statement (experimental).

Parameters:

string sql
SQL query

Return: object


Class: Kohana_Database_Exception

class Kohana_Database_Exception extends Kohana_Exception

Sets the code for a Database exception.


Methods

Kohana_Database_Exception -> __construct

public function __construct

Set exception message.

Parameters:

string error
i18n language key for the message

Kohana_Database_Exception -> __toString

public function __toString

Magic method for converting an object to a string.

Return: string i18n message


Kohana_Database_Exception -> getTemplate

public function getTemplate

Fetch the template name.

Return: string


Kohana_Database_Exception -> sendHeaders

public function sendHeaders

Sends an Internal Server Error header.

Return: void