Methods summary
public
|
#
__construct( array $options = array() )
Constructor
Parameters
Throws
Overrides
|
public
Wei\Record
|
#
__invoke( string $table = null )
Create a new instance of a SQL query builder with specified table name
Create a new instance of a SQL query builder with specified table name
Parameters
- $table
- The name of database table
Returns
|
public
boolean
|
#
connect( )
Connect to the database server
Connect to the database server
Returns
boolean
Throws
|
public
boolean
|
#
isConnected( )
Check if has connected to the database server
Check if has connected to the database server
Returns
boolean
|
public
|
#
close( )
Close the database connection
Close the database connection
|
public
|
#
reconnect( )
Close the current connection and create a new one
Close the current connection and create a new one
|
public
integer
|
#
insert( string $table, array $data )
Executes an INSERT query to insert specified data into table
Executes an INSERT query to insert specified data into table
Parameters
- $table
- The name of table
- $data
- An associative array containing column-value pairs
Returns
integer The number of affected rows
|
public
integer
|
#
insertBatch( string $table, array $data )
Insert batch data into table
Insert batch data into table
Parameters
- $table
- The name of table
- $data
- A two-dimensional array
Returns
integer The number of inserted rows
|
public
integer
|
#
update( string $table, array $data, array $conditions )
Executes a UPDATE query
Parameters
- $table
- The name of table
- $data
- An associative array containing column-value pairs
- $conditions
- The conditions to search records
Returns
integer The number of affected rows
|
public
integer
|
#
delete( string $table, array $conditions )
Executes a DELETE query
Parameters
- $table
- The name of table
- $conditions
- The conditions to search records
Returns
integer The number of affected rows
|
public
array|false
|
#
select( string $table, string|array $conditions, string $select = '*' )
Executes a SELECT query and return the first result
Executes a SELECT query and return the first result
$db->select('user', 1);
$db->select('user', array('username' => 'twin'));
$db->select('user', array('id' => array(1, 2, 3)));
Parameters
- $table
- The name of table
- $conditions
- The "id" key value or an associative array containing column-value pairs
- $select
- The table columns to select
Returns
array|false An associative array containing column-value pairs
|
public
array
|
#
selectAll( string $table, boolean $conditions = false, string $select = '*', integer $limit = null )
Executes a SELECT query and return all results
Executes a SELECT query and return all results
$db->selectAll('user', 1);
$db->selectAll('user', array('username' => 'twin'));
$db->selectAll('user', array('id' => array(1, 2, 3)));
Parameters
- $table
- The name of table
- $conditions
- The "id" key value or an associative array containing column-value pairs
- $select
- The table columns to select
- $limit
- The row number to retrieve
Returns
array
|
public
array|false
|
#
fetch( string $sql, mixed $params = array(), array $types = array() )
Executes a query and returns the first array result
Executes a query and returns the first array result
Parameters
- $sql
- The SQL query
- $params
- The query parameters
- $types
- The parameter types to bind
Returns
array|false Return an array or false when no result found
|
public
array|false
|
#
fetchAll( string $sql, mixed $params = array(), array $types = array() )
Executes a query and returns all array results
Executes a query and returns all array results
Parameters
- $sql
- The SQL query
- $params
- The query parameters
- $types
- The parameter types to bind
Returns
array|false Return an array or false when no result found
|
public
string
|
#
fetchColumn( string $sql, mixed $params = array(), integer $column = 0 )
Executes a query and returns a column value of the first row
Executes a query and returns a column value of the first row
Parameters
- $sql
- The SQL query
- $params
- The query parameters
- $column
- The index of column
Returns
string
|
public
integer
|
#
executeUpdate( string $sql, array $params = array(), array $types = array() )
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
and returns the number of affected rows
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
and returns the number of affected rows
Parameters
- $sql
- The SQL query
- $params
- The query parameters
- $types
- The parameter types to bind
Returns
integer The number of affected rows
|
public
PDOStatement |integer
|
#
query( string $sql, array $params = array(), array $types = array(), boolean $returnRows = false )
Executes an SQL statement, returning a PDOStatement object or the number of affected rows
Executes an SQL statement, returning a PDOStatement object or the number of affected rows
Parameters
- $sql
- The SQL query
- $params
- The SQL parameters
- $types
- The parameter types to bind
- $returnRows
- Whether returns a PDOStatement object or the number of affected rows
Returns
Throws
|
public
integer
|
#
count( string $table, mixed $conditions = false )
Returns the rows number of table search by specified parameters
Returns the rows number of table search by specified parameters
Parameters
Returns
integer
|
public
float
|
#
sum( string $table, string $field, mixed $conditions = false )
Returns the sum of specified table field and conditions
Returns the sum of specified table field and conditions
Parameters
- $table
-
- $field
-
- $conditions
-
Returns
float
|
public
float
|
#
max( string $table, string $field, mixed $conditions = false )
Returns the max value of specified table field and conditions
Returns the max value of specified table field and conditions
Parameters
- $table
-
- $field
-
- $conditions
-
Returns
float
|
public
float
|
#
min( string $table, string $field, mixed $conditions = false )
Returns the min value of specified table field and conditions
Returns the min value of specified table field and conditions
Parameters
- $table
-
- $field
-
- $conditions
-
Returns
float
|
public
float
|
#
avg( string $table, string $field, mixed $conditions = false )
Returns the avg value of specified table field and conditions
Returns the avg value of specified table field and conditions
Parameters
- $table
-
- $field
-
- $conditions
-
Returns
float
|
public
string
|
#
lastInsertId( string $sequence = null )
Returns the ID of the last inserted row or sequence value
Returns the ID of the last inserted row or sequence value
Parameters
- $sequence
- The name of PostgreSQL sequence
Returns
string
|
public
mixed
|
#
errorCode( )
Fetch the SQLSTATE associated with the last operation on the database handle
Fetch the SQLSTATE associated with the last operation on the database handle
Returns
mixed
|
public
array
|
#
errorInfo( )
Fetch extended error information associated with the last operation on the database handle
Fetch extended error information associated with the last operation on the database handle
Returns
array
|
public
Wei\Record
|
#
init( string $table, array $data = array(), boolean $isNew = true )
Init a record instance
Parameters
- $table
- The name of database table
- $data
- The data for table record
- $isNew
- Whether it's a new record and have not save to database
Returns
|
public
Wei\Record |false
|
#
find( string $table, string|array $id )
Find a record from specified table and conditions
Find a record from specified table and conditions
Parameters
- $table
- The name of table
- $id
- The primary key value or an associative array containing column-value pairs
Returns
|
public
Wei\Record
|
#
findOne( string $table, string|array $id )
Find a record from specified table and conditions
and throws 404 exception when record not found
Find a record from specified table and conditions
and throws 404 exception when record not found
Parameters
- $table
-
- $id
- The primary key value or an associative array containing column-value pairs
Returns
Throws
|
public
Wei\Record
|
#
findOrInit( string $table, string $id, array $data = array() )
Find a record, if not found, create a new one from specified data
Find a record, if not found, create a new one from specified data
Parameters
- $table
- The name of table
- $id
- The primary key value or an associative array containing column-value pairs
- $data
- The data to create a new record when record not found
Returns
|
public
Wei\Record
|
#
findAll( string $table, mixed $where = false )
Find records from specified table and conditions
Find records from specified table and conditions
Parameters
- $table
- The name of table
- $where
- The primary key value or an associative array containing column-value pairs
Returns
|
public
mixed
|
#
addRecordClass( string $table, string $class )
Set the record class for specified table
Set the record class for specified table
Parameters
Returns
mixed $this
|
public
string
|
#
getRecordClass( string $table )
Returns the record class name of table
Returns the record class name of table
Parameters
Returns
string The record class name for table
|
public
string
|
#
getTable( string $table )
Returns the full table name with prefix
Returns the full table name with prefix
Parameters
Returns
string
|
public
string
|
#
getUser( )
Returns the database username
Returns the database username
Returns
string
|
public
string
|
#
getPassword( )
Returns the database password
Returns the database password
Returns
string
|
public
string
|
#
getHost( )
Returns the hostname on which the database server resides
Returns the hostname on which the database server resides
Returns
string
|
public
string
|
#
getPort( )
Returns the port on which the database server is running
Returns the port on which the database server is running
Returns
string
|
public
string
|
#
getDbname( )
Returns the name of the database
Returns the name of the database
Returns
string
|
public
string
|
#
getDriver( )
Returns the name of PDO driver
Returns the name of PDO driver
Returns
string
|
public
string
|
#
getDsn( )
Returns the PDO DSN
Returns
string
Throws
|
public
PDO
|
#
getPdo( )
Returns the original PDO object
Returns the original PDO object
Returns
|
public
string
|
#
getTablePrefix( )
Returns the prefix string of table name
Returns the prefix string of table name
Returns
string
|
public
string
|
#
getLastQuery( )
Returns the last executed SQL query
Returns the last executed SQL query
Returns
string
|
public
array
|
#
getQueries( )
Returns all executed SQL queries
Returns all executed SQL queries
Returns
array
|
public
array
|
#
getTableFields( string $table, boolean $withPrefix = false )
Returns the name of fields of specified table
Returns the name of fields of specified table
Parameters
Returns
array
Throws
|
protected
|
#
filter( mixed $data, mixed $name )
|
protected
|
|
protected
|
#
bindParameter( PDOStatement $stmt, array $params, array $types )
Bind parameters to statement object
Bind parameters to statement object
Parameters
|
protected
float
|
#
executeAggregate( string $fn, string $table, string $field, mixed $conditions )
Execute a query with aggregate function
Execute a query with aggregate function
Parameters
- $fn
-
- $table
-
- $field
-
- $conditions
-
Returns
float
|
Properties summary
protected
string
|
$driver
The name of PDO driver, could be mysql, sqlite or pgsql
The name of PDO driver, could be mysql, sqlite or pgsql
|
|
protected
string
|
$user
|
|
protected
string
|
$password
|
|
protected
string
|
$host
The hostname on which the database server resides, for mysql and pgsql
The hostname on which the database server resides, for mysql and pgsql
|
|
protected
string
|
$port
The port on which the database server is running, for mysql and pgsql
The port on which the database server is running, for mysql and pgsql
|
|
protected
string
|
$dbname
The name of the database, for mysql and pgsql
The name of the database, for mysql and pgsql
|
|
protected
string
|
$unixSocket
The MySQL Unix socket (shouldn't be used with host or port), for mysql only
The MySQL Unix socket (shouldn't be used with host or port), for mysql only
|
|
protected
string
|
$charset
The character set, for mysql only
The character set, for mysql only
|
|
protected
string
|
$path
The path for sqlite database
The path for sqlite database
|
|
protected
string
|
$dsn
The dsn parameter for PDO constructor
The dsn parameter for PDO constructor
|
|
protected
array
|
$attrs
A key=>value array of driver-specific connection attributes
A key=>value array of driver-specific connection attributes
Link
|
|
protected
PDO
|
$pdo
|
|
protected
callable
|
$beforeConnect
The callback triggers before connect to database
The callback triggers before connect to database
|
|
protected
callable
|
$connectFails
The callback triggers when fails to connect to database
The callback triggers when fails to connect to database
|
|
protected
callable
|
$afterConnect
The callback triggers after connect to database
The callback triggers after connect to database
|
|
protected
callable
|
$beforeQuery
The callback triggers before execute query
The callback triggers before execute query
|
|
protected
callable
|
$afterQuery
The callback triggers after execute query
The callback triggers after execute query
|
|
protected
boolean
|
$isConnected
Whether connected to the database server
Whether connected to the database server
|
|
protected
array
|
$tables
The database table definitions
The database table definitions
|
|
protected
string
|
$recordClass
The base record class when instance a new record object
The base record class when instance a new record object
|
|
protected
array
|
$recordClasses
An associative array that the key is table name and the value is class name
An associative array that the key is table name and the value is class name
|
|
protected
string
|
$recordNamespace
The record namespace without ending "\"
The record namespace without ending "\"
|
|
protected
string
|
$tablePrefix
|
|
protected
boolean
|
$global
Whether use the options from the default db service
Whether use the options from the default db service
|
|
protected
array
|
$queries
|
|
protected
array
|
$tableFields
|
|
protected
string
|
$slaveDb
The salve db configuration name
The salve db configuration name
|
|