|
pclib
3.2.0
Lightweight PHP framework
|
Simple database wrapper. More...
Public Member Functions | |
| __construct ($dataSource=null) | |
| Establish database connection. More... | |
| connect ($dataSource) | |
| Establish database connection. More... | |
| close () | |
| Close database connection. | |
| codePage ($cp) | |
| Set connection character set. | |
| seek ($res, $rowno) | |
| Seek resource $res to $rowno. | |
| setLimit ($numrows, $offset=0) | |
| The portable way to perform limit. More... | |
| query ($_sql, $param=null) | |
| Perform database query with parameters - return result resource. More... | |
| field ($dsstr) | |
| Perform SELECT query and return value of one database field. More... | |
| select ($dsstr) | |
| Perform SELECT query and return one row of result as assoc-array. More... | |
| selectAll ($dsstr) | |
| Perform SELECT query and return ALL rows of result as assoc-array. More... | |
| selectOne ($dsstr) | |
| Perform SELECT query, return first column of result as indexed array. More... | |
| selectPair ($dsstr) | |
| Perform SELECT query, return first and second column as associative array (lookup query). More... | |
| insert ($tab, $data) | |
| Perform INSERT query, return inserted ID. More... | |
| insertAll ($tab, array $data) | |
| Insert multiple rows. | |
| insertUpdate ($tab, array $data, array $key=['ID']) | |
| Update or insert when key does not exists. More... | |
| runDump ($fileName, $skipErrors=false) | |
| Run database dump file $fileName. More... | |
| replace ($tab, $data) | |
| Perform REPLACE query, return inserted ID. More... | |
| update ($tab, $data, $cond) | |
| Perform UPDATE query. More... | |
| delete ($tab, $cond) | |
| Perform DELETE query. More... | |
| count ($dsstr=null) | |
| Return number of rows in query result / table. More... | |
| exists ($dsstr) | |
| Return true if some row which is satisfying condition exists. More... | |
| fetch ($res=null, $fmt='a') | |
| Fetch one row from query result. More... | |
| fetchAll ($res=null, $fmt='a') | |
| Fetch ALL rows from query result. More... | |
| beginTransaction () | |
| Begins a transaction. | |
| commit () | |
| Commits statements in a transaction. | |
| rollback () | |
| Rollback changes in a transaction. | |
| dbName () | |
| Return current database name. | |
| columns ($table) | |
| Return columns metadata (name,size,type,nullable,default) of table $table as associative array. More... | |
| indexes ($table) | |
| Return indexes for table $table. More... | |
| export ($dba, $fmt='html') | |
| Export query result to format $fmt. More... | |
| getLookup ($lkpName) | |
| Return lookup table as array. More... | |
| escape ($str, $type='string') | |
| Escapes string for use in database query. More... | |
| setParams ($sql, $params) | |
| Place $params into $sql and return result string. More... | |
Public Member Functions inherited from BaseObject | |
| loadDefaults ($className=null) | |
| Load default parameters of class $className into object instance. | |
| setProperties (array $defaults) | |
| Set public properties of object from the array. More... | |
| toArray () | |
| Convert object to array. More... | |
Data Fields | |
| $disabled = false | |
| If enabled, no query is executed. | |
| $lastQuery | |
| SQL of last executed query. | |
| $forceReconnect = true | |
| Create new connection even if connection with same params exists. | |
| $slowQueryLog = 1.0 | |
| Log queries slower than 1s - 0: do not log anything. | |
| $drv | |
| var AbstractDriver Database driver | |
Data Fields inherited from BaseObject | |
| $serviceLocator | |
| var function() Return service object when requested with service(). | |
Protected Member Functions | |
| getSelectSql ($dsstr, $args) | |
| Helper for building SELECT sql. More... | |
| getWhereSql ($cond, $args) | |
| Helper for building WHERE clausule of sql query. More... | |
| isSql ($dsstr, $type='') | |
| True if $dsstr is SQL string (of type $type) | |
Protected Member Functions inherited from BaseObject | |
| service ($service, $default=null) | |
| Try acquire $service and load it into property $this->$service. More... | |
Protected Attributes | |
| $app | |
| var App | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
| static | defaults () |
| Set or retireve default parameters of the object. More... | |
Simple database wrapper.
Features:
| __construct | ( | $dataSource = null | ) |
Establish database connection.
| string | array | $dataSource | Format: 'driver://user:passw@host/database' |
| columns | ( | $table | ) |
Return columns metadata (name,size,type,nullable,default) of table $table as associative array.
| connect | ( | $dataSource | ) |
Establish database connection.
Format of $datasource can be:
| string | array | $dataSource |
| count | ( | $dsstr = null | ) |
Return number of rows in query result / table.
Without parameters it returns number of rows in last query. For using with parameters see examples.
Ex:
| string | $dsstr | Datasource string |
| string | $cond | where condition |
| delete | ( | $tab, | |
| $cond | |||
| ) |
Perform DELETE query.
See Examples of using database functions parameters.
| string | $tab | Table name |
| string | $cond | where condition (required) |
| escape | ( | $str, | |
$type = 'string' |
|||
| ) |
Escapes string for use in database query.
| string | $str | String (parameter) used in sql query |
| exists | ( | $dsstr | ) |
Return true if some row which is satisfying condition exists.
See select() for possible parameters. See Examples of using database functions parameters.
Ex: if($db->exists('PERSONS', 'MONEY>1000')) ...
| string | $dsstr | Datasource string |
| string | $cond | where condition |
| export | ( | $dba, | |
$fmt = 'html' |
|||
| ) |
| fetch | ( | $res = null, |
|
$fmt = 'a' |
|||
| ) |
Fetch one row from query result.
If result is ommited, it uses last query.
| resource | $res | Query result resource |
| string | $fmt | format of result a - assoc, o - object, r - row, ar - array, f - field |
| fetchAll | ( | $res = null, |
|
$fmt = 'a' |
|||
| ) |
Fetch ALL rows from query result.
| resource | $res | Query result resource |
| string | $fmt | format of result |
| field | ( | $dsstr | ) |
Perform SELECT query and return value of one database field.
This function is shortcut for SQL SELECT command. Parameters consist from two parts: datasource string and condition. Datasource can be:
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $dsstr | datasource string. |
| string | $cond | WHERE condition. |
| getLookup | ( | $lkpName | ) |
Return lookup table as array.
| string | $lkpname | Lookup table name |
|
protected |
Helper for building SELECT sql.
|
protected |
Helper for building WHERE clausule of sql query.
| indexes | ( | $table | ) |
Return indexes for table $table.
| insert | ( | $tab, | |
| $data | |||
| ) |
Perform INSERT query, return inserted ID.
See Examples of using database functions parameters.
| string | $tab | Table name |
| array | string | $data | assoc-array of 'FIELDNAME' => 'FIELDVALUE' pairs. |
| insertUpdate | ( | $tab, | |
| array | $data, | ||
| array | $key = ['ID'] |
||
| ) |
Update or insert when key does not exists.
| string | $tab | Table name |
| array | $data | assoc-array of 'FIELDNAME' => 'FIELDVALUE' pairs. |
| array | $key | Found record for update with $key fields |
| query | ( | $_sql, | |
$param = null |
|||
| ) |
Perform database query with parameters - return result resource.
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $_sql | sql-query |
| array | $param | query parameters. |
| replace | ( | $tab, | |
| $data | |||
| ) |
Perform REPLACE query, return inserted ID.
See Examples of using database functions parameters.
| string | $tab | Table name |
| array | string | $data | assoc-array of 'FIELDNAME' => 'FIELDVALUE' pairs. |
| runDump | ( | $fileName, | |
$skipErrors = false |
|||
| ) |
Run database dump file $fileName.
| select | ( | $dsstr | ) |
Perform SELECT query and return one row of result as assoc-array.
This function is shortcut for SQL SELECT command. Parameters consist from two parts: datasource string and condition. Datasource can be:
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $dsstr | datasource string. |
| string | $cond | WHERE condition. |
| selectAll | ( | $dsstr | ) |
Perform SELECT query and return ALL rows of result as assoc-array.
This function is shortcut for SQL SELECT command. Parameters consist from two parts: datasource string and condition. Datasource can be:
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $dsstr | datasource string. |
| string | $cond | WHERE condition. |
| selectOne | ( | $dsstr | ) |
Perform SELECT query, return first column of result as indexed array.
This function is shortcut for SQL SELECT command. Parameters consist from two parts: datasource string and condition. Datasource can be:
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $dsstr | datasource string. |
| string | $cond | WHERE condition. |
| selectPair | ( | $dsstr | ) |
Perform SELECT query, return first and second column as associative array (lookup query).
This function is shortcut for SQL SELECT command. Parameters consist from two parts: datasource string and condition. Datasource can be:
You can use Dynamic SQL. See Examples of using database functions parameters
| string | $dsstr | datasource string. |
| string | $cond | WHERE condition. |
| setLimit | ( | $numrows, | |
$offset = 0 |
|||
| ) |
The portable way to perform limit.
Next query result will be limited according setlimit parameters.
| int | $numrows | number of rows in result |
| int | $offset | offset from which result started |
| setParams | ( | $sql, | |
| $params | |||
| ) |
| update | ( | $tab, | |
| $data, | |||
| $cond | |||
| ) |
Perform UPDATE query.
See Examples of using database functions parameters.
| string | $tab | Table name |
| array | string | $data | array of values. |
| string | $cond | where condition (required). |