Class DibiConnection


dibi connection.

DibiObject
   |
   --DibiConnection
Copyright: Copyright (c) 2005, 2010 David Grudl
Located: in /libs/DibiConnection.php (line 21)
Constructor Summary
public
__construct (array|string|ArrayObject $config, [string $name = NULL])
Creates object and (optionally) connects to a database.
Destructor Summary
public
Automatically frees the resources allocated for this result set.
Method Summary
int
Gets the number of affected rows. Alias for getAffectedRows().
static void
alias (array &$config, string $key, [string $alias = NULL])
Apply configuration alias or default values.
void
applyLimit (string &$sql, int $limit, int $offset)
Injects LIMIT/OFFSET to the SQL query.
void
begin ([string $savepoint = NULL])
Begins a transaction (if supported).
DibiFluent
command ()
void
commit ([string $savepoint = NULL])
Commits statements in a transaction.
protected void
connect ()
Connects to a database.
DibiDataSource
dataSource (array|mixed $args)
Generates (translates) and returns SQL query as DibiDataSource.
DibiFluent
delete (string $table)
string
delimite (string $value)
Delimites identifier (table's or column's name, etc.).
void
Disconnects from a database.
string
escape (string $value, [string $type = dibi::TEXT])
Encodes data for use in a SQL statement.
DibiRow
fetch (array|mixed $args)
Executes SQL query and fetch result - shortcut for query() & fetch().
array
fetchAll (array|mixed $args)
Executes SQL query and fetch results - shortcut for query() & fetchAll().
string
fetchPairs (array|mixed $args)
Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
string
fetchSingle (array|mixed $args)
Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
int
Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
mixed
getConfig ([string $key = NULL], [mixed $default = NULL])
Returns configuration variable. If no $key is passed, returns the entire array.
DibiDatabaseInfo
Gets a information about the current database.
IDibiDriver
Returns the connection resource.
int
getInsertId ([string $sequence = NULL])
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
IDibiProfiler
resource
Returns the connection resource.
DibiFluent
insert (string $table, array $args)
int
insertId ([string $sequence = NULL])
Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
bool
Is in transaction?
bool
Returns TRUE when connection was established.
int
loadFile (string $file)
Import SQL dump from file - extreme fast!
DibiResult|int
nativeQuery (string $sql)
Executes the SQL query.
DibiResult|int
query (array|mixed $args)
Generates (translates) and executes SQL query.
void
rollback ([string $savepoint = NULL])
Rollback changes in a transaction.
DibiFluent
select (string $args)
DibiConnection
setProfiler ([IDibiProfiler $profiler = NULL])
string
sql (array|mixed $args)
Generates and returns SQL query.
bool
test (array|mixed $args)
Generates and prints SQL query.
string
unescape (string $value, [string $type = dibi::BINARY])
Decodes data from result set.
DibiFluent
update (string $table, array $args)
void
__sleep ()
Prevents serialization.
void
Prevents unserialization.
Methods Inherited From DibiObject
DibiObject::extensionMethod(), DibiObject::getClass(), DibiObject::getReflection(), DibiObject::__call(), DibiObject::__callStatic(), DibiObject::__get(), DibiObject::__isset(), DibiObject::__set(), DibiObject::__unset()

Constructor Details

line 43

__construct

public __construct (array|string|ArrayObject $config, [string $name = NULL])

Creates object and (optionally) connects to a database.

Input
array|string|ArrayObject $config connection parameters
string $name connection name
Destructor details

line 110

__destruct

public void __destruct ()

Automatically frees the resources allocated for this result set.

Method Details

line 364

affectedRows

public int affectedRows ()

Gets the number of affected rows. Alias for getAffectedRows().

Output
int number of rows
Throws
throws DibiException

line 192

alias

public static void alias (array &$config, string $key, [string $alias = NULL])

Apply configuration alias or default values.

Input
array &$config connect configuration
string $key key
string $alias alias key
Output
void  

line 519

applyLimit

public void applyLimit (string &$sql, int $limit, int $offset)

Injects LIMIT/OFFSET to the SQL query.

Input
string &$sql The SQL query that will be modified.
int $limit
int $offset
Output
void  
Tags
Deprecated

line 404

begin

public void begin ([string $savepoint = NULL])

Begins a transaction (if supported).

Input
string $savepoint optional savepoint name
Output
void  

line 534

command

public DibiFluent command ()

Output
DibiFluent  

line 423

commit

public void commit ([string $savepoint = NULL])

Commits statements in a transaction.

Input
string $savepoint optional savepoint name
Output
void  

line 122

connect

protected void connect ()

Connects to a database.

Output
void  

line 290

dataSource

public DibiDataSource dataSource (array|mixed $args)

Generates (translates) and returns SQL query as DibiDataSource.

Input
array|mixed $args one or more arguments
Output
DibiDataSource  
Throws
throws DibiException

line 590

delete

public DibiFluent delete (string $table)

Input
string $table table
Output
DibiFluent  

line 503

delimite

public string delimite (string $value)

Delimites identifier (table's or column's name, etc.).

Input
string $value identifier
Output
string delimited identifier
Tags
Deprecated

line 142

disconnect

public void disconnect ()

Disconnects from a database.

Output
void  

line 473

escape

public string escape (string $value, [string $type = dibi::TEXT])

Encodes data for use in a SQL statement.

Input
string $value unescaped string
string $type type (dibi::TEXT, dibi::BOOL, ...)
Output
string escaped and quoted string
Tags
Deprecated

line 633

fetch

public DibiRow fetch (array|mixed $args)

Executes SQL query and fetch result - shortcut for query() & fetch().

Input
array|mixed $args one or more arguments
Output
DibiRow  
Throws
throws DibiException

line 647

fetchAll

public array fetchAll (array|mixed $args)

Executes SQL query and fetch results - shortcut for query() & fetchAll().

Input
array|mixed $args one or more arguments
Output
array of DibiRow
Throws
throws DibiException

line 675

fetchPairs

public string fetchPairs (array|mixed $args)

Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().

Input
array|mixed $args one or more arguments
Output
string  
Throws
throws DibiException

line 661

fetchSingle

public string fetchSingle (array|mixed $args)

Executes SQL query and fetch first column - shortcut for query() & fetchSingle().

Input
array|mixed $args one or more arguments
Output
string  
Throws
throws DibiException

line 350

getAffectedRows

public int getAffectedRows ()

Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.

Output
int number of rows
Throws
throws DibiException

line 170

getConfig

public mixed getConfig ([string $key = NULL], [mixed $default = NULL])

Returns configuration variable. If no $key is passed, returns the entire array.

Input
string $key
mixed $default default value to use if key not found
Output
mixed  
Tags
See self::__construct

line 724

getDatabaseInfo

public DibiDatabaseInfo getDatabaseInfo ()

Gets a information about the current database.

Output
DibiDatabaseInfo  

line 210

getDriver

public IDibiDriver getDriver ()

Returns the connection resource.

Output
IDibiDriver  

line 377

getInsertId

public int getInsertId ([string $sequence = NULL])

Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.

Input
string $sequence optional sequence name
Output
int  
Throws
throws DibiException

line 616

getProfiler

public IDibiProfiler getProfiler ()

Output
IDibiProfiler  

line 222

getResource

public resource getResource ()

Returns the connection resource.

Output
resource  
Tags
Deprecated use getDriver()->getResource()

line 573

insert

public DibiFluent insert (string $table, array $args)

Input
string $table table
array $args
Output
DibiFluent  

line 392

insertId

public int insertId ([string $sequence = NULL])

Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().

Input
string $sequence optional sequence name
Output
int  
Throws
throws DibiException

line 458

inTransaction

public bool inTransaction ()

Is in transaction?

Output
bool  

line 156

isConnected

public bool isConnected ()

Returns TRUE when connection was established.

Output
bool  

line 692

loadFile

public int loadFile (string $file)

Import SQL dump from file - extreme fast!

Input
string $file filename
Output
int count of sql commands

line 306

nativeQuery

public DibiResult|int nativeQuery (string $sql)

Executes the SQL query.

Input
string $sql SQL statement.
Output
DibiResult|int result set object (if any)
Throws
throws DibiException

line 236

query

public DibiResult|int query (array|mixed $args)

Generates (translates) and executes SQL query.

Input
array|mixed $args one or more arguments
Output
DibiResult|int result set object (if any)
Throws
throws DibiException

line 441

rollback

public void rollback ([string $savepoint = NULL])

Rollback changes in a transaction.

Input
string $savepoint optional savepoint name
Output
void  

line 545

select

public DibiFluent select (string $args)

Input
string $args column name
Output
DibiFluent  

line 605

setProfiler

public DibiConnection setProfiler ([IDibiProfiler $profiler = NULL])

Input
IDibiProfiler $profiler
Output
DibiConnection provides a fluent interface

line 252

sql

public string sql (array|mixed $args)

Generates and returns SQL query.

Input
array|mixed $args one or more arguments
Output
string  
Throws
throws DibiException

line 267

test

public bool test (array|mixed $args)

Generates and prints SQL query.

Input
array|mixed $args one or more arguments
Output
bool  

line 489

unescape

public string unescape (string $value, [string $type = dibi::BINARY])

Decodes data from result set.

Input
string $value value
string $type type (dibi::BINARY)
Output
string decoded value
Tags
Deprecated

line 558

update

public DibiFluent update (string $table, array $args)

Input
string $table table
array $args
Output
DibiFluent  

line 745

__sleep

public void __sleep ()

Prevents serialization.

Output
void  

line 735

__wakeup

public void __wakeup ()

Prevents unserialization.

Output
void