Overview

Packages

  • tipy

Classes

  • Tipy
  • TipyApp
  • TipyCli
  • TipyCliSession
  • TipyConfig
  • TipyController
  • TipyCookie
  • TipyDAO
  • TipyEnv
  • TipyFlash
  • TipyInflector
  • TipyInput
  • TipyIOWrapper
  • TipyLogger
  • TipyMailer
  • TipyModel
  • TipyOutput
  • TipyRequest
  • TipySession
  • TipyTestCase
  • TipyTestRunner
  • TipyView

Exceptions

  • AssertionFailedException
  • CompileErrorException
  • CompileWarningException
  • CoreErrorException
  • CoreWarningException
  • DeprecatedException
  • NoMethodException
  • NoticeException
  • ParseException
  • RecoverableErrorException
  • StrictException
  • TipyDaoException
  • TipyException
  • TipyModelException
  • TipyRollbackException
  • TipyValidationException
  • UserDeprecatedException
  • UserErrorException
  • UserNoticeException
  • UserWarningException
  • WarningException
  • Overview
  • Package
  • Class
  • Deprecated
  • Todo

Class TipyDAO

Database connection wrapper with basic database functions

Direct known subclasses

TipyModel
Package: tipy
Located at src/TipyDAO.php
Methods summary
public
# __construct( )

Connect to database

Connect to database

public mysqli_result
# query( string $sql, array $params = null )

Query database

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

TipyDaoException
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();
// Select rows 6-15
$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

TipyDaoException
public integer
# numRows( mysqli & $result )

Return the number of rows from $result

Return the number of rows from $result

Parameters

$result

Returns

integer
public array
# fetchRow( mysqli & $result )

Return row as associative array from $result

Return row as associative array from $result

Parameters

$result
$results

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

$result
$results

Returns

array
public array
# queryRow( string $sql, array $params = null )

Query and fetch one row

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

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

$closure
public static
# rollback( )

Rollback transaction

Rollback transaction

Throws TipyRollbackException inside TipyDAO::transaction() try-catch statement. If exception is not caught then TipyDAO::rollback() was called outside transaction.

Throws

TipyRollbackException
public static boolean
# isTransactionInProgress( )

Return true if there is transaction in progress

Return true if there is transaction in progress

Returns

boolean
Properties summary
protected mysqli|null $dbLink

MySQL database connection

MySQL database connection

#
public TipyLogger $logger
#
tipy API documentation generated by ApiGen