Methods summary
public
|
|
public
mysqli_result
|
#
query( string $sql, array $params = null )
Query database
$dao = new TipyDAO();
$result = $dao->query('select * from users where first_name=? and last_name=?', ['john', 'doe']);
Parameters
- $sql
- SQL template with ? placeholders
- $params
- Array with values to fill placeholders
Returns
mysqli_result
Throws
|
public
mysqli_result
|
#
limitQuery( string $sql, integer $offset, integer $limit, array $params = null )
Return the number of rows limited by $limit starting from $offset
Return the number of rows limited by $limit starting from $offset
$dao = new TipyDAO();
$result = $dao->imitQuery('select * from users', 5, 10);
Parameters
- $sql
- SQL template with ? placeholders
- $offset
- offset of the first row
- $limit
- number of rows to return
- $params
- Array with values to fill placeholders
Returns
mysqli_result
Throws
|
public
integer
|
#
numRows( mysqli & $result )
Return the number of rows from $result
Return the number of rows from $result
Parameters
Returns
integer
|
public
array
|
#
fetchRow( mysqli & $result )
Return row as associative array from $result
Return row as associative array from $result
Parameters
Returns
array
|
public
array
|
#
fetchAllRows( mysqli & $result )
Return all rows as array of associative arrays from $result
Return all rows as array of associative arrays from $result
Parameters
Returns
array
|
public
array
|
#
queryRow( string $sql, array $params = null )
Query and fetch one row
Parameters
- $sql
- SQL template with ? placeholders
- $params
- Array with values to fill placeholders
Returns
array
|
public
array
|
#
queryAllRows( string $sql, array $params = null )
Query and fetch all rows
Parameters
- $sql
- SQL template with ? placeholders
- $params
- Array with values to fill placeholders
Returns
array
|
public
array|null
|
#
limitQueryAllRows( string $sql, integer $offset, integer $limit, array $params = null )
Query and fetch all rows with paginated query
Query and fetch all rows with paginated query
Parameters
- $sql
- SQL template with ? placeholders
- $offset
- offset of the first row
- $limit
- number of rows to return
- $params
- Array with values to fill placeholders
Returns
array|null
|
public
integer|string
|
#
lastInsertId( )
Return id auto generated by the last insert query
Return id auto generated by the last insert query
By default returns integer but tf the number is greater
than maximal int value then return string
Returns
integer|string
|
public
integer|string
|
#
affectedRows( )
Return the number of rows affected by the last query
Return the number of rows affected by the last query
By default returns integer but tf the number is greater
than maximal int value then return string
Returns
integer|string
|
public static
|
#
transaction( Closure $closure )
Execute $closure() inside SQL transaction block
Execute $closure() inside SQL transaction block
TipyModel::transaction(function() {
$model = new MyModel();
$model->attribute = 'value';
$model->save();
});
To rollback transaction call TipyDAO::rollback()
TipyModel::transaction(function() {
$model = new MyModel();
$model->attribute = 'value';
$model->save();
TipyModel::rollback();
});
To use current scope variables inside closure
$a = 1;
$b = 2;
TipyModel::transaction(function() use ($a, $b) {
echo $a + $b;
});
Parameters
|
public static
|
#
rollback( )
Rollback transaction
Throws TipyRollbackException inside TipyDAO::transaction() try-catch statement.
If exception is not caught then TipyDAO::rollback() was called outside transaction.
Throws
|
public static
boolean
|
#
isTransactionInProgress( )
Return true if there is transaction in progress
Return true if there is transaction in progress
Returns
boolean
|