프로퍼티 | 타입 | 설명 | |
---|---|---|---|
$bulkInsertSize | integer | Large inserts are broken up into multiple insert of this size | |
$debug | integer | Debugging turned on(1) or off(0) | |
$errorCntr | integer | Number of errors that have been generated | |
$errorCode | string | The last error code that was generated | |
$errorMsg | string | The last error message that was generated | |
$errors | array | List of errors that have been generated | |
$insertId | integer | Last insert ID | |
$instanceCntr | integer | Number of instances that have been created | |
$lastQuery | string | The last query that was run | |
$maxProfiling | integer | Maximum number of items to retain in profiling list | |
$selectResult | array | Default storage variable for select result if no variable is provided | |
$useErrorLog | integer | Also log errors via error_log |
메소드 | 설명 | |
---|---|---|
__construct ( mixed $host, string $username = null, string $password = null, string $db = null, $label = 'n/a' ) | Initialize an instance of the database class. | |
__destruct ( ) | Actions to perform when class is destructed | |
clearResult ( ) | Clear $selectResult variable | |
connect ( $useMaster = false, $reconnect = false ) : mixed | Establish a connection to the database. Note: Connections are "on demand", you shouldn't need to call this function yourself Called automatically by execQuery if no connection. | |
delete ( $tablename, $filter, $filterBindings = null, boolean $useMaster = true, $modifiers = '' ) : integer | Delete records from the database | |
disconnect ( boolean $useMaster = false ) | Disconnect from the database | |
execute ( $bindings = [], boolean $useMaster = false ) : integer | Execute a prepare statement to data binding values. Can be called repeatedly for the same prepared query, with different data bindings. | |
fetch ( boolean $useMaster = false, constant $method = null ) : array | Fetch one row of data from the database after SELECT query is run | |
fetchAll ( variable &$resultVar, string $keyField = null, boolean $grouped = false, boolean $useMaster = false, constant $method = null ) : integer | Fetch all rows from the database after SELECT query is run Rows can be fetched with a field as the index instead of sequential index By specifying a $keyField and $grouped, record will be returned grouped by the key field | |
fetchField ( string $fieldName, boolean $useMaster = false ) : array | Fetch a single field from a select query. Use for when you just want a list of values, like IDs, for processing. | |
foundRows ( boolean $useMaster = false ) : integer | Retrieve total rows found for last SELECT SQL_CALC_FOUND_ROWS query with LIMIT clause | |
getLastInsertId ( boolean $useMaster = true ) : integer | Get the last insert if for prepare/execute statements | |
getProfiling ( ) : array | Retrieve profiling information | |
getResult ( variable &$resultVar ) : array | Retrieve the contents of the $selectResult class variable and clear it | |
getServerInstance ( mixed $serverKey, boolean $new = false ) | Return an instance of the class connected to the specified server If any instance of the request server already exist, that instance will be returned | |
insert ( string $tablename, array &$data, string $modifiers = '', boolean $useMaster = true, string $action = 'INSERT' ) : integer | Insert record(s) in database. The last insert ID is stored in the $insertId class variable | |
prepare ( string $query, boolean $useMaster = false, array $attr = null ) | Prepare a query for execution by the execPrepared function | |
rawQuery ( string $query, boolean $useMaster = false ) : integer | Execute query. Can be called directly for complex query. | |
resetProfiling ( ) | Resets the profiling array | |
select ( string $query, array $bindings = null, boolean $useMaster = false, boolean $fetchAll = false ) : integer | Run a SELECT query with optional data binding values | |
selectAll ( string $query, array $bindings = null, boolean $useMaster = false ) : mixed | Run a SELECT query with optional data binding values, and retrieves ALL rows This will use a separate statement handle so other outstanding queries do not get overwritten | |
selectOne ( string $query, array $bindings = null, boolean $useMaster = false ) : mixed | Run a SELECT query with optional data binding values, and retrieve only 1 row | |
setConnectParams ( mixed $host, string $username = null, string $password = null, string $db = null, string $label = 'n/a', array $attr = null ) | Set database connection parameters. This does not establish a connection, only sets the parameters for a connection. | |
setConnectParamsMaster ( mixed $connectParams ) | Set MASTER database connection parameters. This does not establish a connection, only sets the parameters for a connection. | |
setConnectTimeout ( integer $value, boolean $useMaster = false ) | Set how long a db connection will be left open before disconnecting | |
setServerConfig ( array $servers, mixed $masterKey = null ) | Set Server Connection Parameters The server list can have all the fields listed in $connectDefaults. At a minimum, it should have a lablel | |
update ( string $tablename, array $data, string $filter, string $filterBindings = null, boolean $useMaster = true ) : integer | Update record(s) in database |
메소드 | 설명 | |
---|---|---|
connectMaster ( $reconnect = false ) : mixed | Establish a connection to the Master server | |
explainQuery ( string $query, array $bindings = null, object &$dbh ) | Run and EXPLAIN on a query for debugging puroposes. | |
logErrorInfo ( object $handle, $label = '' ) | Log an error that occurred on a handle (database or statement) | |
updateProfiling ( string $query, array $bindings, float $qTime, string $result, string $label, mixed $debug = null ) | Update profiling array with query information |
public __construct ( mixed $host, string $username = null, string $password = null, string $db = null, $label = 'n/a' ) | ||
$host | mixed | string (hostname) or associative array with parameter to use |
$username | string | user name to use for login |
$password | string | password to use for login |
$db | string | optional database to select |
public disconnect ( boolean $useMaster = false ) | ||
$useMaster | boolean | disconnect from master/slave |
public fetchAll ( variable &$resultVar, string $keyField = null, boolean $grouped = false, boolean $useMaster = false, constant $method = null ) : integer | ||
$resultVar | variable | variable reference to store the result in |
$keyField | string | field to use as the array key |
$grouped | boolean | if $keyField specified, group by the key field |
$useMaster | boolean | set to TRUE to use the master server connection |
$method | constant | PDO method to use for fetch records (default is PDO::FETCH_ASSOC) |
리턴 | integer | 1 if successful, -1 if error. Fetched data is stored in $selectResult class variable by default |
public getLastInsertId ( boolean $useMaster = true ) : integer | ||
$useMaster | boolean | set to TRUE to use the master server connection |
리턴 | integer | lsat insert id |
public static getServerInstance ( mixed $serverKey, boolean $new = false ) | ||
$serverKey | mixed | the $servers key to use for connecting |
$new | boolean | force the creation of a new instance |
public insert ( string $tablename, array &$data, string $modifiers = '', boolean $useMaster = true, string $action = 'INSERT' ) : integer | ||
$tablename | string | name of table to insert into |
$data | array | associative array of field/value pairs to insert, can be multi-dimensional for bulk inserts. All fields must be the same for each record for bulk inserts |
$modifiers | string | modifier to use in query (i.e. IGNORE). Default is no modifier |
$useMaster | boolean | set to TRUE to use the master server connection |
$action | string | type of insert to perform (INSERT, REPLACE). Default is INSERT |
리턴 | integer | number of rows that were inserted |
public prepare ( string $query, boolean $useMaster = false, array $attr = null ) | ||
$query | string | the query string, may contain data binding placeholder for use by execPrepared |
$useMaster | boolean | set to TRUE to use the master server connection |
$attr | array | custom PDO attributes to set $return int whether statement was successfully prepared (1), or not (-1) |
public select ( string $query, array $bindings = null, boolean $useMaster = false, boolean $fetchAll = false ) : integer | ||
$query | string | SQL Select query to run |
$bindings | array | array of values to bind to the query. Can be an associative array to bind by name |
$useMaster | boolean | set to TRUE to use the master server connection |
$fetchAll | boolean | 1 to fetch data into an associated array ($this->selectResult), 0 to just run the query (use on of the fetch/fetchAll functions to retrieve data) |
리턴 | integer | returns number of rows selected. Use SQL_CALC_FOUND_ROWS with qFoundRows if using LIMIT, to get total rows found. |
public selectAll ( string $query, array $bindings = null, boolean $useMaster = false ) : mixed | ||
$query | string | SQL Select query to run |
$bindings | array | array of values to bind to the query. Can be an associative array to bind by name |
$useMaster | boolean | set to TRUE to use the master server connection |
리턴 | mixed | returns associative array of data on success, negative int on failure |
public selectOne ( string $query, array $bindings = null, boolean $useMaster = false ) : mixed | ||
$query | string | SQL Select query to run |
$bindings | array | array of values to bind to the query. Can be an associative array to bind by name |
$useMaster | boolean | set to TRUE to use the master server connection |
리턴 | mixed | returns associative array of data on success, negative int on failure |
public setConnectParams ( mixed $host, string $username = null, string $password = null, string $db = null, string $label = 'n/a', array $attr = null ) | ||
$host | mixed | string (hostname) or associative array with parameter to use |
$username | string | user name to use for login |
$password | string | password to use for login |
$db | string | optional database to select |
$label | string | a "name" reference for the connection, used for profiling |
$attr | array | connection attribute list (i.e. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") |
public static setConnectParamsMaster ( mixed $connectParams ) | ||
$connectParams | mixed | associative array with parameters to use, see setConnectParams function |
public setConnectTimeout ( integer $value, boolean $useMaster = false ) | ||
$value | integer | seconds before timeout |
$useMaster | boolean | set timeout value on master/slave connection |
public static setServerConfig ( array $servers, mixed $masterKey = null ) | ||
$servers | array | list of servers to connect to. The array key should be the "id" of the server. |
$masterKey | mixed | the array key in $servers that acts as the Master server |
public update ( string $tablename, array $data, string $filter, string $filterBindings = null, boolean $useMaster = true ) : integer | ||
$tablename | string | name of table to update |
$data | array | associative array of field/value pairs to update. Note only raw data is supported, not formulas |
$filter | string | SQL filter to apply to update, should be properly escaped |
$filterBindings | string | associative array name/value pairs to use for binding. CAUTION: may override $data bindings if same names are used |
$useMaster | boolean | set to TRUE to use the master server connection |
리턴 | integer | number of rows updated, or negative if an error occurred |
public int $bulkInsertSize | ||
리턴 | integer |
public static int $errorCntr | ||
리턴 | integer |
public static array $errors | ||
리턴 | array |
public static int $instanceCntr | ||
리턴 | integer |
public static int $maxProfiling | ||
리턴 | integer |
public array $selectResult | ||
리턴 | array |