Base class for data access objects.
More...
|
| transactionStart () |
| Start a new transaction.
|
|
| transactionCommit () |
| Commit a transaction.
|
|
| transactionRollback () |
| Rollback a transaction.
|
|
| bind ( $stmt, $values) |
| Bind values to a prepared statement.
|
|
| fetch ( $sql, $params=null) |
| Prepare and execute an SQL statement and return the first row of results.
|
|
| fetchAll ( $sql, $params=null) |
| Prepare and execute an SQL statement and return all results.
|
|
| fetchAllWithFound ( $sql, $params=null) |
| Prepare and execute an SQL statement and return all results plus the number of rows found on the server side.
|
|
| update ( $sql, $params=null) |
| Prepare and execute an SQL statement in a transaction.
|
|
| insert ( $sql, $params=null) |
| Prepare and execute an SQL statement in a transaction.
|
|
|
static | buildWhere (array $where, $conjunction='AND') |
| Construct a where clause.
|
|
static | buildHaving (array $having, $conjunction='AND') |
| Construct a having clause.
|
|
static | buildBooleanClause ( $type, array $expressions, $conjunction='AND') |
| Construct a boolean clause.
|
|
static | concat () |
| Create a string by joining all arguments with spaces.
|
|
static | makeBindParams (array $list) |
| Create a list of bind parameters from a list of strings.
|
|
|
| $dbh |
|
| $logger |
|
| $transactionCounter = 0 |
|
Base class for data access objects.
- Author
- Bryan Davis bd808.nosp@m.@wik.nosp@m.imedi.nosp@m.a.or.nosp@m.g
- Copyright
- © 2015 Bryan Davis, Wikimedia Foundation and contributors.
◆ __construct()
Wikimedia\Slimapp\Dao\AbstractDao::__construct |
( |
| $dsn, |
|
|
| $user, |
|
|
| $pass, |
|
|
| $logger = null ) |
- Parameters
-
string | $dsn | PDO data source name |
string | $user | Database user |
string | $pass | Database password |
LoggerInterface | $logger | Log channel |
◆ bind()
Wikimedia\Slimapp\Dao\AbstractDao::bind |
( |
| $stmt, |
|
|
| $values ) |
|
protected |
Bind values to a prepared statement.
If an associative array of values is provided, the data type to use when binding will be inferred by looking for a "<type>_" prefix at the beginning of the array key. This can come in very handy if you are using parameters in places like LIMIT clauses where binding as a string (the default type for PDO binds) will cause a syntax error.
- Parameters
-
PDOStatement | $stmt | Previously prepared statement |
array | $values | Values to bind |
◆ buildBooleanClause()
static Wikimedia\Slimapp\Dao\AbstractDao::buildBooleanClause |
( |
| $type, |
|
|
array | $expressions, |
|
|
| $conjunction = 'AND' ) |
|
staticprotected |
Construct a boolean clause.
- Parameters
-
string | $type | Clause type (eg 'WHERE', 'HAVING') |
array | $expressions | List of expressions |
string | $conjunction | Joining operation ('AND' or 'OR') |
- Returns
- string Clause or empty string
◆ buildHaving()
static Wikimedia\Slimapp\Dao\AbstractDao::buildHaving |
( |
array | $having, |
|
|
| $conjunction = 'AND' ) |
|
staticprotected |
Construct a having clause.
- Parameters
-
array | $having | List of conditions |
string | $conjunction | Joining operation ('and' or 'or') |
- Returns
- string Having clause or empty string
◆ buildWhere()
static Wikimedia\Slimapp\Dao\AbstractDao::buildWhere |
( |
array | $where, |
|
|
| $conjunction = 'AND' ) |
|
staticprotected |
Construct a where clause.
- Parameters
-
array | $where | List of conditions |
string | $conjunction | Joining operation ('and' or 'or') |
- Returns
- string Where clause or empty string
◆ concat()
static Wikimedia\Slimapp\Dao\AbstractDao::concat |
( |
| ) |
|
|
staticprotected |
Create a string by joining all arguments with spaces.
If one or more of the arguments are arrays each element of the array will be included independently.
- Returns
- string New string
◆ fetch()
Wikimedia\Slimapp\Dao\AbstractDao::fetch |
( |
| $sql, |
|
|
| $params = null ) |
|
protected |
Prepare and execute an SQL statement and return the first row of results.
- Parameters
-
string | $sql | SQL |
array | $params | Prepared statement parameters |
- Returns
- array First response row
◆ fetchAll()
Wikimedia\Slimapp\Dao\AbstractDao::fetchAll |
( |
| $sql, |
|
|
| $params = null ) |
|
protected |
Prepare and execute an SQL statement and return all results.
- Parameters
-
string | $sql | SQL |
array | $params | Prepared statement parameters |
- Returns
- array Result rows
◆ fetchAllWithFound()
Wikimedia\Slimapp\Dao\AbstractDao::fetchAllWithFound |
( |
| $sql, |
|
|
| $params = null ) |
|
protected |
Prepare and execute an SQL statement and return all results plus the number of rows found on the server side.
The SQL is expected to contain the "SQL_CALC_FOUND_ROWS" option in the select statement. If it does not, the number of found rows returned is dependent on MySQL's interpretation of the query.
- Parameters
-
string | $sql | SQL |
array | $params | Prepared statement parameters |
- Returns
- stdClass StdClass with rows and found members
◆ insert()
Wikimedia\Slimapp\Dao\AbstractDao::insert |
( |
| $sql, |
|
|
| $params = null ) |
|
protected |
Prepare and execute an SQL statement in a transaction.
- Parameters
-
string | $sql | SQL |
array | null | $params | Prepared statement parameters |
- Returns
- string|false Last insert id or false if an exception was generated
◆ makeBindParams()
static Wikimedia\Slimapp\Dao\AbstractDao::makeBindParams |
( |
array | $list | ) |
|
|
staticprotected |
Create a list of bind parameters from a list of strings.
- Parameters
-
array | $list | List of strings to convert to bind parameters |
- Returns
- array List of bind parameters (eg ':field1)
◆ transactionCommit()
Wikimedia\Slimapp\Dao\AbstractDao::transactionCommit |
( |
| ) |
|
|
protected |
Commit a transaction.
If the transaction counter is zero, commit the transaction otherwise decrement the transaction counter. This method is useful in nested transactions.
- Returns
- bool True on success, false on failure.
◆ transactionRollback()
Wikimedia\Slimapp\Dao\AbstractDao::transactionRollback |
( |
| ) |
|
|
protected |
Rollback a transaction.
If the transaction counter is greater than 0, set it to 0 and rollback the transaction. This method is useful in nested transactions.
- Returns
- bool True on success, false on failure.
◆ transactionStart()
Wikimedia\Slimapp\Dao\AbstractDao::transactionStart |
( |
| ) |
|
|
protected |
Start a new transaction.
If already a transaction has been started, it will only increment the counter. This method is useful in nested transactions.
- Returns
- bool True on success, false on failure.
◆ update()
Wikimedia\Slimapp\Dao\AbstractDao::update |
( |
| $sql, |
|
|
| $params = null ) |
|
protected |
Prepare and execute an SQL statement in a transaction.
- Parameters
-
string | $sql | SQL |
array | $params | Prepared statement parameters |
- Returns
- bool False if an exception was generated, true otherwise
The documentation for this class was generated from the following file: