DataTables Database connection object.
Create a database connection which may then have queries performed upon
it.
This is a database abstraction class that can be used on multiple different
databases. As a result of this, it might not be suitable to perform complex
queries through this interface or vendor specific queries, but everything
required for basic database interaction is provided through the abstracted
methods.
Methods summary
public
|
|
#
__construct( $opts )
Database instance constructor.
Database instance constructor.
Parameters
- $opts
string[]
$opts Array of connection parameters for the database:
array(
"user" => "",
"pass" => "",
"host" => "",
"port" => "",
"db" => "",
"type" => ""
)
|
public
|
self
|
#
commit( )
Commit a database transaction.
|
public
|
DataTables\Database\Result
|
#
delete( $table, $where = null )
Perform a delete query on a table.
Perform a delete query on a table.
This is a short cut method that creates an update query and then uses the
query('delete'), table, where and exec methods of the query.
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $where
array
$where Where condition for what to delete - see DataTables\Query::where.
Returns
|
public
|
DataTables\Database\Result
|
#
insert( $table, $set )
Insert data into a table.
Insert data into a table.
This is a short cut method that creates an update query and then uses the
query('insert'), table, set and exec methods of the query.
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $set
array
$set Field names and values to set - see DataTables\Query::set.
Returns
|
public
|
DataTables\Database\Result
|
#
push( $table, $set, $where = null )
Update or Insert data. When doing an insert, the where condition is added as
a set field
Update or Insert data. When doing an insert, the where condition is added as
a set field
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $set
array
$set Field names and values to set - see DataTables\Query::set.
- $where
array
$where Where condition for what to delete - see DataTables\Query::where.
Returns
|
public
|
DataTables\Database\Query
|
#
query( $type, $table = null )
Create a query object to build a database query.
Create a query object to build a database query.
Parameters
- $type
string
$type Query type - select, insert, update or delete.
- $table
string|string[]
$table Table name(s) to act upon.
Returns
|
public
|
string
|
#
quote( $val, $type = \PDO::PARAM_STR )
Quote a string for a quote. Note you should generally use a bind!
Quote a string for a quote. Note you should generally use a bind!
Parameters
- $val
string
$val Value to quote
- $type
string
$type Value type
Returns
string
|
public
|
self
|
#
rollback( )
Rollback the database state to the start of the transaction.
|
public
|
DataTables\Database\Result
|
#
select( $table, $field = "*", $where = null, $orderBy = null )
Select data from a table.
Select data from a table.
This is a short cut method that creates an update query and then uses the
query('select'), table, get, where and exec methods of the query.
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $field
array
$field Fields to get from the table(s) - see DataTables\Query::get.
- $where
array
$where Where condition for what to delete - see DataTables\Query::where.
- $orderBy
array
$orderBy Order condition - see DataTables\Query::order.
Returns
|
public
|
DataTables\Database\Result
|
#
selectDistinct( $table, $field = "*", $where = null, $orderBy = null )
Select data from a table.
Select data from a table.
This is a short cut method that creates an update query and then uses the
query('select'), table, get, where and exec methods of the query.
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $field
array
$field Fields to get from the table(s) - see DataTables\Query::get.
- $where
array
$where Where condition for what to delete - see DataTables\Query::where.
- $orderBy
array
$orderBy Order condition - see DataTables\Query::order.
Returns
|
public
|
DataTables\Database\Result
|
#
sql( $sql )
Execute an raw SQL query - i.e. give the method your own SQL, rather than
having the Database classes building it for you.
Execute an raw SQL query - i.e. give the method your own SQL, rather than
having the Database classes building it for you.
Parameters
- $sql
string
$sql SQL string to execute (only if _type is 'raw').
Returns
Example
Basic select
$result = $db->sql( 'SELECT * FROM myTable;' );
Set the character set of the connection
$db->sql("SET character_set_client=utf8");
$db->sql("SET character_set_connection=utf8");
$db->sql("SET character_set_results=utf8");
|
public
|
self
|
|
public
|
DataTables\Database\Result
|
#
update( $table, $set = null, $where = null )
Update data.
This is a short cut method that creates an update query and then uses the
query('update'), table, set, where and exec methods of the query.
Parameters
- $table
string|string[]
$table Table name(s) to act upon.
- $set
array
$set Field names and values to set - see DataTables\Query::set.
- $where
array
$where Where condition for what to delete - see DataTables\Query::where.
Returns
|