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( string[] $opts )
Database instance constructor.
Database instance constructor.
Parameters
- $opts
Array of connection parameters for the database:
array(
"user" => "",
"pass" => "",
"host" => "",
"port" => "",
"db" => "",
"type" => ""
)
|
public
DataTables\Database
|
#
commit( )
Commit a database transaction.
|
public
DataTables\Database\Result
|
#
delete( string|string[] $table, array $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
- Table name(s) to act upon.
- $where
Where condition for what to delete - see Query::where.
Returns
|
public
DataTables\Database\Result
|
#
insert( string|string[] $table, array $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
- Table name(s) to act upon.
- $set
Field names and values to set - see Query::set.
Returns
|
public
DataTables\Database\Result
|
#
push( string|string[] $table, array $set, array $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
- Table name(s) to act upon.
- $set
Field names and values to set - see Query::set.
- $where
Where condition for what to update - see Query::where.
Returns
|
public
DataTables\Database\Query
|
#
query( string $type, string|string[] $table = null )
Create a query object to build a database query.
Create a query object to build a database query.
Parameters
- $type
- Query type - select, insert, update or delete.
- $table
- Table name(s) to act upon.
Returns
|
public
string
|
#
quote( string $val, string $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
- Value to quote
- $type
- Value type
Returns
string
|
public
DataTables\Database\Result
|
#
raw( string $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.
This method will execute the given SQL immediately. Use the raw()
method if you need the ability to add bound parameters.
Parameters
- $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
DataTables\Database
|
#
rollback( )
Rollback the database state to the start of the transaction.
|
public
DataTables\Database\Result
|
#
select( string|string[] $table, array $field = "*", array $where = null, array $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
- Table name(s) to act upon.
- $field
Fields to get from the table(s) - see Query::get.
- $where
Where condition for what to select - see Query::where.
- $orderBy
Order condition - see Query::order.
Returns
|
public
DataTables\Database\Result
|
#
selectDistinct( string|string[] $table, array $field = "*", array $where = null, array $orderBy = null )
Select distinct data from a table.
Select distinct data from a table.
This is a short cut method that creates an update query and then uses the
query('select'), distinct ,table, get, where and exec methods of the
query.
Parameters
- $table
- Table name(s) to act upon.
- $field
Fields to get from the table(s) - see Query::get.
- $where
Where condition for what to select - see Query::where.
- $orderBy
Order condition - see Query::order.
Returns
|
public
DataTables\Database\Result
|
#
sql( string $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.
This method will execute the given SQL immediately. Use the raw()
method if you need the ability to add bound parameters.
Parameters
- $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
DataTables\Database
|
|
public
DataTables\Database\Result
|
#
update( string|string[] $table, array $set = null, array $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
- Table name(s) to act upon.
- $set
Field names and values to set - see Query::set.
- $where
Where condition for what to update - see Query::where.
Returns
|