Alpha Framework 4.0.0 API Documentation

ActiveRecordProviderMySQL
in package
implements ActiveRecordProviderInterface

MySQL active record provider (uses the MySQLi native API in PHP).

Tags
since
1.1
author

John Collins dev@alphaframework.org

license

http://www.opensource.org/licenses/bsd-license.php The BSD License

copyright

Copyright (c) 2022, John Collins (founder of Alpha Framework). All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.
* Neither the name of the Alpha Framework nor the names
  of its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Table of Contents

Interfaces

ActiveRecordProviderInterface
An interface that defines all of the active record methods that should be included in a provider that implements this interface.

Properties

$connection  : Mysqli
Datebase connection.
$logger  : Logger
Trace logger.
$record  : ActiveRecord
The business object that we are mapping back to.

Methods

__construct()  : mixed
The constructor.
addProperty()  : void
(non-PHPdoc).
backupDatabase()  : void
(non-PHPdoc).
begin()  : void
(non-PHPdoc).
checkDatabaseExists()  : bool
(non-PHPdoc).
checkRecordExists()  : bool
(non-PHPdoc).
checkRecordTableExists()  : bool
(non-PHPdoc).
checkTableExists()  : bool
(non-PHPdoc).
checkTableNeedsUpdate()  : bool
(non-PHPdoc).
commit()  : void
(non-PHPdoc).
createDatabase()  : void
(non-PHPdoc).
createForeignIndex()  : void
(non-PHPdoc).
createUniqueIndex()  : void
(non-PHPdoc).
delete()  : void
(non-PHPdoc).
disconnect()  : void
(non-PHPdoc).
dropDatabase()  : void
(non-PHPdoc).
dropTable()  : void
(non-PHPdoc).
findMissingFields()  : array<string|int, mixed>
(non-PHPdoc).
getConnection()  : Mysqli
(non-PHPdoc).
getCount()  : int
(non-PHPdoc).
getHistoryCount()  : int
(non-PHPdoc).
getIndexes()  : array<string|int, mixed>
(non-PHPdoc).
getLastDatabaseError()  : string
(non-PHPdoc).
getMAX()  : int
(non-PHPdoc).
getVersion()  : int
(non-PHPdoc).
isTableOverloaded()  : bool
(non-PHPdoc).
load()  : void
(non-PHPdoc).
loadAll()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByAttribute()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByAttributes()  : array<string|int, mixed>
(non-PHPdoc).
loadAllByDayUpdated()  : array<string|int, mixed>
(non-PHPdoc).
loadAllFieldValuesByAttribute()  : array<string|int, mixed>
(non-PHPdoc).
loadAllOldVersions()  : array<string|int, mixed>
(non-PHPdoc).
loadByAttribute()  : void
(non-PHPdoc).
makeHistoryTable()  : void
(non-PHPdoc).
makeTable()  : void
(non-PHPdoc).
query()  : array<string|int, mixed>
(non-PHPdoc).
rebuildTable()  : void
(non-PHPdoc).
reload()  : void
(non-PHPdoc).
rollback()  : void
(non-PHPdoc).
save()  : void
(non-PHPdoc).
saveAttribute()  : void
(non-PHPdoc).
saveHistory()  : void
(non-PHPdoc).
setEnumOptions()  : void
(non-PHPdoc).
setRecord()  : void
(non-PHPdoc).
bindParams()  : mysqli_stmt
Dynamically binds all of the attributes for the current Record to the supplied prepared statement parameters. If arrays of attribute names and values are provided, only those will be bound to the supplied statement.
bindResult()  : array<string|int, mixed>
Dynamically binds the result of the supplied prepared statement to a 2d array, where each element in the array is another array representing a database row.
checkIndexes()  : void
Checks to see if all of the indexes are in place for the record's table, creates those that are missing.
findOffendingValue()  : string
Parses a MySQL error for the value that violated a unique constraint.

Properties

Methods

addProperty()

(non-PHPdoc).

public addProperty(mixed $propName) : void
Parameters
$propName : mixed

The name of the new field to add to the database table.

Tags
see
ActiveRecordProviderInterface::addProperty()

backupDatabase()

(non-PHPdoc).

public static backupDatabase(mixed $targetFile) : void
Parameters
$targetFile : mixed
Tags
see
ActiveRecordProviderInterface::backupDatabase()

checkDatabaseExists()

(non-PHPdoc).

public static checkDatabaseExists() : bool
Tags
see
ActiveRecordProviderInterface::checkDatabaseExists()
Return values
bool

checkRecordExists()

(non-PHPdoc).

public checkRecordExists(mixed $ID) : bool
Parameters
$ID : mixed

The Object ID of the object we want to see whether it exists or not.

Tags
see
ActiveRecordProviderInterface::checkRecordExists()
Return values
bool

checkRecordTableExists()

(non-PHPdoc).

public static checkRecordTableExists(mixed $RecordClassName[, mixed $checkHistoryTable = false ]) : bool
Parameters
$RecordClassName : mixed

The name of the business object class we are checking.

$checkHistoryTable : mixed = false

Set to true if you want to check for the existance of the _history table for this DAO.

Tags
see
ActiveRecordProviderInterface::checkRecordTableExists()
Return values
bool

checkTableExists()

(non-PHPdoc).

public checkTableExists([mixed $checkHistoryTable = false ]) : bool
Parameters
$checkHistoryTable : mixed = false

Set to true if you want to check for the existance of the _history table for this DAO.

Tags
see
ActiveRecordProviderInterface::checkTableExists()
Return values
bool

checkTableNeedsUpdate()

(non-PHPdoc).

public checkTableNeedsUpdate() : bool
Tags
see
ActiveRecordProviderInterface::checkTableNeedsUpdate()
Return values
bool

createDatabase()

(non-PHPdoc).

public static createDatabase() : void
Tags
see
ActiveRecordProviderInterface::createDatabase()

createForeignIndex()

(non-PHPdoc).

public createForeignIndex(mixed $attributeName, mixed $relatedClass, mixed $relatedClassAttribute[, mixed $indexName = null ]) : void
Parameters
$attributeName : mixed

The name of the attribute to apply the index on.

$relatedClass : mixed

The fully-qualified name of the related class.

$relatedClassAttribute : mixed

The name of the field to relate to on the related class.

$indexName : mixed = null

The optional name for the index, will calculate if not provided.

Tags
see
ActiveRecordProviderInterface::createForeignIndex()

createUniqueIndex()

(non-PHPdoc).

public createUniqueIndex(mixed $attribute1Name[, mixed $attribute2Name = '' ][, mixed $attribute3Name = '' ]) : void
Parameters
$attribute1Name : mixed

The first attribute to mark unique in the database.

$attribute2Name : mixed = ''

The second attribute to mark unique in the databse (optional, use only for composite keys).

$attribute3Name : mixed = ''

The third attribute to mark unique in the databse (optional, use only for composite keys).

Tags
see
ActiveRecordProviderInterface::createUniqueIndex()

disconnect()

(non-PHPdoc).

public static disconnect() : void
Tags
see
ActiveRecordProviderInterface::disconnect()

dropDatabase()

(non-PHPdoc).

public static dropDatabase() : void
Tags
see
ActiveRecordProviderInterface::dropDatabase()

dropTable()

(non-PHPdoc).

public dropTable([mixed $tableName = null ]) : void
Parameters
$tableName : mixed = null

Optional table name, leave blank for the defined table for this class to be dropped

Tags
see
ActiveRecordProviderInterface::dropTable()

findMissingFields()

(non-PHPdoc).

public findMissingFields() : array<string|int, mixed>
Tags
see
ActiveRecordProviderInterface::findMissingFields()
Return values
array<string|int, mixed>

getConnection()

(non-PHPdoc).

public static getConnection() : Mysqli
Tags
see
ActiveRecordProviderInterface::getConnection()
Return values
Mysqli

getCount()

(non-PHPdoc).

public getCount([mixed $attributes = array() ][, mixed $values = array() ]) : int
Parameters
$attributes : mixed = array()

The attributes to count the objects by (optional).

$values : mixed = array()

The values of the attributes to count the objects by (optional).

Tags
see
ActiveRecordProviderInterface::getCount()
Return values
int

getHistoryCount()

(non-PHPdoc).

public getHistoryCount() : int
Tags
see
ActiveRecordProviderInterface::getHistoryCount()
Return values
int

getIndexes()

(non-PHPdoc).

public getIndexes() : array<string|int, mixed>
Tags
see
ActiveRecordProviderInterface::getIndexes()
Return values
array<string|int, mixed>

getLastDatabaseError()

(non-PHPdoc).

public static getLastDatabaseError() : string
Tags
see
ActiveRecordProviderInterface::getLastDatabaseError()
Return values
string

getMAX()

(non-PHPdoc).

public getMAX() : int
Tags
see
ActiveRecordProviderInterface::getMAX()
Return values
int

getVersion()

(non-PHPdoc).

public getVersion() : int
Tags
see
ActiveRecordProviderInterface::getVersion()
Return values
int

isTableOverloaded()

(non-PHPdoc).

public isTableOverloaded() : bool
Tags
see
ActiveRecordProviderInterface::isTableOverloaded()
Return values
bool

load()

(non-PHPdoc).

public load(mixed $ID[, mixed $version = 0 ]) : void
Parameters
$ID : mixed

The object ID of the record to load.

$version : mixed = 0

Optionaly, provide the version to load that version from the [tablename]_history table.

Tags
see
ActiveRecordProviderInterface::load()

loadAll()

(non-PHPdoc).

public loadAll([mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

Tags
see
ActiveRecordProviderInterface::loadAll()
Return values
array<string|int, mixed>

loadAllByAttribute()

(non-PHPdoc).

public loadAllByAttribute(mixed $attribute, mixed $value[, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ][, mixed $constructorArgs = array() ]) : array<string|int, mixed>
Parameters
$attribute : mixed

The attribute to load the objects by.

$value : mixed

The value of the attribute to load the objects by.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of objects to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the objects by.

$order : mixed = 'ASC'

The order to sort the objects by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type.

$constructorArgs : mixed = array()

An optional array of contructor arguements to pass to the records that will be generated and returned. Supports a maximum of 5 arguements.

Tags
see
ActiveRecordProviderInterface::loadAllByAttribute()
Return values
array<string|int, mixed>

loadAllByAttributes()

(non-PHPdoc).

public loadAllByAttributes([mixed $attributes = array() ][, mixed $values = array() ][, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ][, mixed $constructorArgs = array() ]) : array<string|int, mixed>
Parameters
$attributes : mixed = array()

The attributes to load the records by.

$values : mixed = array()

The values of the attributes to load the records by.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

$constructorArgs : mixed = array()

An optional array of contructor arguements to pass to the records that will be generated and returned. Supports a maximum of 5 arguements.

Tags
see
ActiveRecordProviderInterface::loadAllByAttributes()
Return values
array<string|int, mixed>

loadAllByDayUpdated()

(non-PHPdoc).

public loadAllByDayUpdated(mixed $date[, mixed $start = 0 ][, mixed $limit = 0 ][, mixed $orderBy = 'ID' ][, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$date : mixed

The date for which to load the records updated on, in the format 'YYYY-MM-DD'.

$start : mixed = 0

The start of the SQL LIMIT clause, useful for pagination.

$limit : mixed = 0

The amount (limit) of records to load, useful for pagination.

$orderBy : mixed = 'ID'

The name of the field to sort the records by.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

Tags
see
ActiveRecordProviderInterface::loadAllByDayUpdated()
Return values
array<string|int, mixed>

loadAllFieldValuesByAttribute()

(non-PHPdoc).

public loadAllFieldValuesByAttribute(mixed $attribute, mixed $value, mixed $returnAttribute[, mixed $order = 'ASC' ][, mixed $ignoreClassType = false ]) : array<string|int, mixed>
Parameters
$attribute : mixed

The attribute name to load the field values by.

$value : mixed

The value of the attribute to load the field values by.

$returnAttribute : mixed

The name of the attribute to return.

$order : mixed = 'ASC'

The order to sort the records by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type.

Tags
see
ActiveRecordProviderInterface::loadAllFieldValuesByAttribute()
Return values
array<string|int, mixed>

loadAllOldVersions()

(non-PHPdoc).

public loadAllOldVersions(mixed $ID) : array<string|int, mixed>
Parameters
$ID : mixed

The object ID of the record to load.

Tags
see
ActiveRecordProviderInterface::loadAllOldVersions()
Return values
array<string|int, mixed>

loadByAttribute()

(non-PHPdoc).

public loadByAttribute(mixed $attribute, mixed $value[, mixed $ignoreClassType = false ][, mixed $loadAttributes = array() ]) : void
Parameters
$attribute : mixed

The name of the attribute to load the record by.

$value : mixed

The value of the attribute to load the record by.

$ignoreClassType : mixed = false

Default is false, set to true if you want to load from overloaded tables and ignore the class type

$loadAttributes : mixed = array()

The attributes to load from the database to this object (leave blank to load all attributes)

Tags
see
ActiveRecordProviderInterface::loadByAttribute()

makeHistoryTable()

(non-PHPdoc).

public makeHistoryTable() : void
Tags
see
ActiveRecordProviderInterface::makeHistoryTable()

makeTable()

(non-PHPdoc).

public makeTable([mixed $checkIndexes = true ]) : void
Parameters
$checkIndexes : mixed = true

Set to false if you do not want to check for any additional required indexes while creating the table (default is true).

Tags
see
ActiveRecordProviderInterface::makeTable()

query()

(non-PHPdoc).

public query(mixed $sqlQuery) : array<string|int, mixed>
Parameters
$sqlQuery : mixed
Tags
see
ActiveRecordProviderInterface::query()
Return values
array<string|int, mixed>

rebuildTable()

(non-PHPdoc).

public rebuildTable() : void
Tags
see
ActiveRecordProviderInterface::rebuildTable()

rollback()

(non-PHPdoc).

public static rollback() : void
Tags
see
ActiveRecordProviderInterface::rollback()

saveAttribute()

(non-PHPdoc).

public saveAttribute(mixed $attribute, mixed $value) : void
Parameters
$attribute : mixed

The name of the attribute to save.

$value : mixed

The value of the attribute to save.

Tags
see
ActiveRecordProviderInterface::saveAttribute()

saveHistory()

(non-PHPdoc).

public saveHistory() : void
Tags
see
ActiveRecordProviderInterface::saveHistory()

setEnumOptions()

(non-PHPdoc).

public setEnumOptions() : void
Tags
see
ActiveRecordProviderInterface::setEnumOptions()
since
1.1

setRecord()

(non-PHPdoc).

public setRecord(mixed $record) : void
Parameters
$record : mixed
Tags
see
ActiveRecordProviderInterface::setRecord()

bindParams()

Dynamically binds all of the attributes for the current Record to the supplied prepared statement parameters. If arrays of attribute names and values are provided, only those will be bound to the supplied statement.

private bindParams(mysqli_stmt $stmt[, mixed $attributes = array() ][, mixed $values = array() ]) : mysqli_stmt
Parameters
$stmt : mysqli_stmt

The SQL statement to bind to.

$attributes : mixed = array()
$values : mixed = array()
Tags
since
1.1
Return values
mysqli_stmt

bindResult()

Dynamically binds the result of the supplied prepared statement to a 2d array, where each element in the array is another array representing a database row.

private bindResult(mysqli_stmt $stmt) : array<string|int, mixed>
Parameters
$stmt : mysqli_stmt
Tags
since
1.1
Return values
array<string|int, mixed>

checkIndexes()

Checks to see if all of the indexes are in place for the record's table, creates those that are missing.

private checkIndexes() : void
Tags
since
1.1

findOffendingValue()

Parses a MySQL error for the value that violated a unique constraint.

private findOffendingValue(mixed $error) : string
Parameters
$error : mixed
Tags
since
1.1
Return values
string

        
On this page

Search results