Documentation

DataAccessPoint
in package

Access Point

Example

$accessPoint = App::$dataAccessPoints->Get('main');

# Retrieving data by query

class Queries {
    const TestSelectQuery = '
           select *
           from test
           where id=[[id:integer]] and text=[[text:string]] and dbl=[[dbl::double]]';
}
$reader = $accessPoint->Query(
            Queries::TestSelectQuery, [
                'page' => 1, 'pagesize' => 10, 'params' => [
                    'id' => 1, 'text' => 'adfadf', 'dbl' => 1.1
                ]
            ]);
while($result = $reader->Read()) {
    print_r($result); // object
}

# or without parameters

$reader = $accessPoint->Query('
    select *
    from test
    where id=\'2\' and text=\'adfasdfasdf\' and dbl=\'1.1\'', ['page' => 1, 'pagesize' => 10]);
while($result = $reader->Read()) {
    print_r($result); // object
}

$accessPoint->Query('BEGIN');

# If you need to execute an insert, update, or delete query
$nonQueryInfo = $accessPoint->Query('
    delete from test where id=1', ['type' => DataAccessPoint::QueryTypeNonInfo]);

# If you need to execute a query with a large amount of data, for example, for queries with auto-fetching
$reader = $accessPoint->Query('
    select * from test', ['page' => 1, 'pagesize' => 100, 'type' => DataAccessPoint::QueryTypeBigData]);

# Input data
$nonQueryInfo = $accessPoint->Insert('test', [
    'text' => 'адфасдфасдфасдф', 'dbl' => 1.1], 'id'); # only for postgresql
# It returns a QueryInfo class, for postgres, an additional parameter returning is required -
    the name of the field to return

# Data update
$returnsBool = $accessPoint->Update('test', ['text' => 'adfasdfasdf', 'dbl' => 1.2], 'id=1');
# Returns true if the update was successful

# Input with data update, if there is a duplicate on the identity field or sequence for postgresql
$nonQueryInfo = $accessPoint->InsertOrUpdate('test', [
    'id' => 1, 'text' => 'adfadsfads', 'dbl' => 1.1], ['id', 'text'], 'id');
# The returning field is only needed for postgres
# It returns a QueryInfo class, for postgres, an additional parameter returning is required -
    the name of the field to return

# Batch data input
$nonQueryInfo = $accessPoint->InsertBatch('test', [ [
    'text' => 'adsfasdf', 'dbl' => 1.0], ['text' => 'adsfasdf', 'dbl' => 1.1] ]);

$accessPoint->Query('COMMIT');

# Data deletion
$returnsBool = $accessPoint->Delete('test', 'id=1');
# Returns true if the deletion was successful, note that if
    you do not pass the condition parameter, the table test will be truncated

# Getting a list of tables
$tablesReader = $accessPoint->Tables();
# Returns an IDataReader

Table of Contents

Constants

QueryTypeBigData  = 'bigdata'
Execute the query and return a Reader, but without counting the total number of rows.
QueryTypeNonInfo  = 'noninfo'
Execute a query that does not involve reading data.
QueryTypeReader  = 'reader'
Execute the query and return a Reader
TransationReadonly  = 'readonly'
Readonly transation
TransationReadWrite  = 'readwrite'
ReadWrite transaction

Properties

$connection  : IConnection
$name  : string
$point  : object
$_accessPointData  : object
Connection properties
$_connection  : IConnection
Connection object

Methods

__construct()  : mixed
Constructor
__get()  : mixed
Magic get method
Begin()  : void
Starts a transaction.
Commit()  : void
Commits the transaction.
Delete()  : QueryInfo
Deletes a row based on criteria.
Insert()  : QueryInfo
Inserts a new row.
InsertBatch()  : QueryInfo
Inserts multiple rows at once.
InsertOrUpdate()  : QueryInfo
Inserts a new row or updates an existing one if index fields match.
Query()  : IDataReader|QueryInfo|null
Executes a query in the access point.
Rollback()  : void
Rolls back the transaction.
Tables()  : IDataReader|null
Returns a list of tables in the database.
Update()  : QueryInfo|null
Updates a row.

Constants

QueryTypeBigData

Execute the query and return a Reader, but without counting the total number of rows.

public mixed QueryTypeBigData = 'bigdata'

QueryTypeNonInfo

Execute a query that does not involve reading data.

public mixed QueryTypeNonInfo = 'noninfo'

QueryTypeReader

Execute the query and return a Reader

public mixed QueryTypeReader = 'reader'

TransationReadonly

Readonly transation

public mixed TransationReadonly = 'readonly'

TransationReadWrite

ReadWrite transaction

public mixed TransationReadWrite = 'readwrite'

Properties

$_accessPointData

Connection properties

private object $_accessPointData

Methods

__construct()

Constructor

public __construct(object $accessPointData) : mixed
Parameters
$accessPointData : object

The access point data object.

__get()

Magic get method

public __get(string $property) : mixed
Parameters
$property : string

property connection,point or table name

Begin()

Starts a transaction.

public Begin([string|null $type = null ]) : void
Parameters
$type : string|null = null

Delete()

Deletes a row based on criteria.

public Delete(string $table[, string $condition = '' ]) : QueryInfo
Parameters
$table : string

The table.

$condition : string = ''

The condition.

Return values
QueryInfo

Insert()

Inserts a new row.

public Insert(string $table[, array<string|int, mixed> $row = [] ][, string $returning = '' ][, array<string|int, mixed>|null $params = null ]) : QueryInfo
Parameters
$table : string

The name of the table.

$row : array<string|int, mixed> = []

The row to be inserted.

$returning : string = ''

The name of the field whose value needs to be returned. (For MySQL, this can be omitted, and the value of the identity field will be returned.)

$params : array<string|int, mixed>|null = null
Return values
QueryInfo

InsertBatch()

Inserts multiple rows at once.

public InsertBatch(string $table[, array<string|int, mixed> $rows = [] ]) : QueryInfo
Parameters
$table : string

The table.

$rows : array<string|int, mixed> = []

The rows to be inserted.

Return values
QueryInfo

InsertOrUpdate()

Inserts a new row or updates an existing one if index fields match.

public InsertOrUpdate(string $table[, array<string|int, mixed> $row = [] ][, array<string|int, mixed> $exceptFields = [] ][, string $returning = '' ]) : QueryInfo

A great way to avoid worrying about whether a row exists in the database or not. Works slower than regular data insertion, so use with caution.

Parameters
$table : string

The table.

$row : array<string|int, mixed> = []

The row to be inserted.

$exceptFields : array<string|int, mixed> = []

Which fields to exclude from updating if the row exists based on index fields.

$returning : string = ''

The name of the field whose value needs to be returned. (For MySQL, this can be omitted, and the value of the identity field will be returned.)

Return values
QueryInfo

Query()

Executes a query in the access point.

public Query(string $query[, object|array<string|int, mixed> $commandParams = [] ]) : IDataReader|QueryInfo|null
! Attention
! To execute a query with parameters, do the following:
! 1. Parameters are passed in double square brackets [[param:type]], where type can be integer, double, string, or blob.
! 2. Parameters are passed in an associative array or as an object.
! For example: select * from test where id=[[id:integer]] and stringfield like [[likeparam:string]]
! The actual query with parameters ['id' => '1', 'likeparam' => '%brbrbr%'] will be:
! select * from test where id=1 and stringfield like '%brbrbr%'
! Queries can be put into a collection and executed with different parameters.
Parameters
$query : string

The query string.

$commandParams : object|array<string|int, mixed> = []

[ page, pagesize, params, type = bigdata|noninfo|reader (default reader), returning = '' ]

Return values
IDataReader|QueryInfo|null

Returns an IDataReader object, a QueryInfo object, or null.

Update()

Updates a row.

public Update(string $table, array<string|int, mixed> $row, string $condition[, array<string|int, mixed>|null $params = null ]) : QueryInfo|null
Parameters
$table : string

The table.

$row : array<string|int, mixed>

The row to be updated.

$condition : string

The update condition.

$params : array<string|int, mixed>|null = null
Return values
QueryInfo|null

        
On this page

Search results