Helper for execute queries
| package | salt\sql |
|---|
beginTransaction()
\salt\SaltException |
if PDO->beginTransaction() failed |
|---|
checkAllTransactionsEnded()
\salt\SaltException |
if one transaction is in progress |
|---|
checkPassword(string $name, string $pass) : boolean
stringid of a registered database
stringpassword to check
booleanTRUE if successfull connect to database with this passwordcommit()
\salt\SaltException |
|---|
execCountQuery(\salt\Query $query) : integer
\salt\Querythe query to execute
integernumber of rowsexecCreate(\salt\CreateTableQuery $query)
\salt\CreateTableQuerythe CreateTable query
\salt\SaltException |
if called during a transaction |
|---|
execDelete(\salt\DeleteQuery $query, integer $expected = -1) : integer
\salt\DeleteQuerythe query to execute
integernumber of expected delete, NULL for unknown
\salt\RowCountException |
if delete don't change the expected number of rows |
|---|
integerthe number of rows deletedexecInsert(\salt\InsertQuery $query) : string
\salt\InsertQuerythe query to execute
\salt\RowCountException |
if query don't insert the expected number of objects |
|---|
string\PDO::lastInsertId()execQuery(\salt\Query $query, \salt\Pagination $pagination= NULL, \salt\Base $bindingObject= NULL) : \salt\DBResult
If $pagination is provided and not locked, a count query is also executed
\salt\Querythe query
\salt\PaginationPagination object.
\salt\Base(Optional) bind to another object type. All returned objects are in NEW state instead of LOADED
\salt\DBResultresult of the queryexecSQL(string $sql, array $binds= array(), integer|NULL $expectedRows= NULL) : \salt\SqlStatement
stringsql text
arrayarray of placeholder (key => value). If we want to set the type for bind a value, we can suffix the key by @
followed by a PDOPARAM* constant
For example : Par exemple, array(':param@'.PDO::PARAM_INT => 3)
value can also be an array with two keys for compatibily with classic queries : array('value' => value, 'type' => FieldType)
integerNULLcheck the number of rows affected by the query. NULL for ignoring
\salt\SqlStatementStatement after query executionexecUpdate(\salt\UpdateQuery $query, integer $expected = -1) : integer
\salt\UpdateQuery
integernumber of expected modified rows. NULL if unknown
integernumber of modified rows.getDatabase(string $type = NULL) : string
stringid of a previously registered database, or NULL for default registered database
\salt\SaltException |
if $type is unknown |
|---|
stringdatabase namegetInstance(string $type = NULL) : \salt\DBHelper
stringid of a previously registered database, or NULL for default registered database
\salt\SaltException |
if $type is unknown or connexion failed |
|---|
\salt\DBHelperthe database resourcegetLastError() : array | boolean
arrayboolean
getLastId(string $name = NULL) : string
inTransaction() : boolean
booleanTRUE if we are in a transactionregister(string $name, string $host, string $port, string $db, string $user, string $pass, string $charset, array $options = array())
| see | for mysql charset list |
|---|
stringthe id of the database. Used for retrieve the instance with DBHelper::getInstance(name)
stringhost name
stringport
stringdatabase name
stringuser name
stringpassword of user
stringcharset of database
arrayPDO options array
registerDefault(string $name, string $host, string $port, string $db, string $user, string $pass, string $charset, array $options = array())
| see | for mysql charset list |
|---|
stringthe id of the database. Used for retrieve the instance with DBHelper::getInstance()
stringhost name
stringport
stringdatabase name
stringuser name
stringpassword of user
stringcharset of database
arrayPDO options array
\salt\SaltException |
if database already defined |
|---|
rollback()
\salt\SaltException |
|---|
__construct(\PDO $pdo, string $type)
\PDOthe PDO instance to use in this DBHelper instance
stringtype of the instance
addDebugData(string $sql, array<mixed,mixed> $binds, float|NULL $temps)
stringSQL text query (can be count or not count query)
array<mixed,mixed>placeholders (key => value)
floatNULLexecution time or NULL if query failed
exec(\salt\Query $query, boolean $count= FALSE, \salt\Pagination $pagination= NULL) : \salt\SqlStatement
\salt\Querythe query
booleantrue if count query have to be executed
\salt\Paginationpagination if required
\salt\DBException |
if prepare or execute query failed with a PDOException |
|---|---|
\salt\SaltException |
if something else failed |
\salt\SqlStatementthe statement after executionflattenSqlQuery(string $sql, array<mixed,mixed> $binds) : string
stringSQL query string
array<mixed,mixed>binds, in multiple format, as input/output parameter
stringmodified SQL query string$allDatas : array<mixed,\salt\DBConnexion>
array()$allInstances : array<mixed,\salt\DBHelper>
array()$base : \PDO
NULL$default : string
NULL$txLevel : integer
0$txRollback : boolean
false$type : string
NULL