PDOMySQL
in package
Table of Contents
- $db : mixed
- __construct() : mixed
- addFieldsToTable() : PDOStatement|false
- Execute the query to add fields to a table
- addUniqueCombinedIndex() : bool
- Query to add the unique key constraint on a relation table
- beginTransaction() : void
- If not frozen, start transaction
- bindValues() : void
- Bind parameters to the PDOStatement
- commit() : void
- If not frozen, commit transaction
- connect() : bool
- Connect to PDO
- createTable() : PDOStatement|false
- Execute the query to create a table
- delete() : bool
- Query to delete a record by id
- deleteCollection() : bool
- Delete a collection of Flex models
- deleteQuery() : bool
- Query to delete from a relation table
- find() : array<string|int, mixed>|false
- Helper method to do quick finds For complex queries use PDO directly.
- findOne() : mixed
- Alias for 'find' which just returns the first result and limits the query to one result.
- getCollectionIds() : array<string|int, mixed>
- Get an array of ids from a Flex collection
- getDefaultOptions() : array<string|int, mixed>
- Get default options for queries
- getFieldsAndValues() : array<string|int, mixed>
- Get all the fields and their values from a Flex model
- getTableFields() : array<string|int, mixed>|false
- Get the table fields via DESCRIBE query
- insert() : bool
- Query to insert a model Sets the inserted ID in the model instance.
- insertCollection() : bool
- Insert a model collection in the database using transactions All the models are inserted in one query.
- nullifyUnusedChilds() : bool
- Query to set to null childs of a 'Has' relation
- query() : array<string|int, mixed>
- Execute any query and get an array or a collection of models If the query has any parameters, they have to be prepared to avoid injection so name them in the PDO fashion and send an array of parameters/values.
- rollback() : void
- If not frozen, rollback transaction
- tableExists() : bool
- Check if a table exists via query
- unusedChildsQuery() : bool
- Query used to delet unused childs in 'Has' or 'HasAndBelongs' relations
- update() : bool
- Query to update a model
- updateTableTypes() : void
- Update field types on the model table
Properties
$db
public
mixed
$db
Methods
__construct()
public
__construct() : mixed
Return values
mixed —addFieldsToTable()
Execute the query to add fields to a table
public
addFieldsToTable(string $name, array<string|int, mixed> $fields) : PDOStatement|false
Parameters
- $name : string
-
Table name
- $fields : array<string|int, mixed>
Return values
PDOStatement|false —addUniqueCombinedIndex()
Query to add the unique key constraint on a relation table
public
addUniqueCombinedIndex(Flex $model) : bool
Parameters
- $model : Flex
Return values
bool —beginTransaction()
If not frozen, start transaction
public
beginTransaction() : void
Return values
void —bindValues()
Bind parameters to the PDOStatement
public
bindValues(PDOStatement $stmt[, array<string|int, mixed> $params = [] ]) : void
Parameters
- $stmt : PDOStatement
- $params : array<string|int, mixed> = []
Return values
void —commit()
If not frozen, commit transaction
public
commit() : void
Return values
void —connect()
Connect to PDO
public
connect(mixed $params) : bool
Parameters
- $params : mixed
Tags
Return values
bool —createTable()
Execute the query to create a table
public
createTable(string $name) : PDOStatement|false
Parameters
- $name : string
Return values
PDOStatement|false —delete()
Query to delete a record by id
public
delete(mixed $table, Flex $model) : bool
Parameters
- $table : mixed
- $model : Flex
Return values
bool —deleteCollection()
Delete a collection of Flex models
public
deleteCollection(array<string|int, Flex> $collection) : bool
Parameters
- $collection : array<string|int, Flex>
Return values
bool —deleteQuery()
Query to delete from a relation table
public
deleteQuery(Flex $model, Relation $relation) : bool
Parameters
Return values
bool —find()
Helper method to do quick finds For complex queries use PDO directly.
public
find(string $table[, string $condition = '' ][, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|false
Parameters
- $table : string
- $condition : string = ''
- $params : array<string|int, mixed> = []
- $options : array<string|int, mixed> = []
Return values
array<string|int, mixed>|false —findOne()
Alias for 'find' which just returns the first result and limits the query to one result.
public
findOne(mixed $table[, string $condition = '' ][, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $table : mixed
- $condition : string = ''
- $params : array<string|int, mixed> = []
- $options : array<string|int, mixed> = []
Return values
mixed —getCollectionIds()
Get an array of ids from a Flex collection
public
getCollectionIds(array<string|int, Flex> $collection) : array<string|int, mixed>
Parameters
- $collection : array<string|int, Flex>
Return values
array<string|int, mixed> —getDefaultOptions()
Get default options for queries
public
getDefaultOptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFieldsAndValues()
Get all the fields and their values from a Flex model
public
getFieldsAndValues(Flex $model) : array<string|int, mixed>
Parameters
- $model : Flex
Return values
array<string|int, mixed> —getTableFields()
Get the table fields via DESCRIBE query
public
getTableFields(string $name) : array<string|int, mixed>|false
Parameters
- $name : string
Return values
array<string|int, mixed>|false —insert()
Query to insert a model Sets the inserted ID in the model instance.
public
insert(Flex $model, mixed $table, mixed $data) : bool
Parameters
- $model : Flex
- $table : mixed
- $data : mixed
Return values
bool —insertCollection()
Insert a model collection in the database using transactions All the models are inserted in one query.
public
insertCollection(array<string|int, Flex> $inserts) : bool
Parameters
- $inserts : array<string|int, Flex>
Tags
Return values
bool —nullifyUnusedChilds()
Query to set to null childs of a 'Has' relation
public
nullifyUnusedChilds(Flex $model, Relation $relation, mixed $ids) : bool
Parameters
Return values
bool —query()
Execute any query and get an array or a collection of models If the query has any parameters, they have to be prepared to avoid injection so name them in the PDO fashion and send an array of parameters/values.
public
query(mixed $query[, mixed $params = [] ][, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Eg: $query = 'SELECT * FROM user WHERE id = :id'; $params = [':id' => $id];
In the $options parameter define if you want hydration, which is enabled by default to return a collection of Flex models.
In the case of Flex models, if the table name option is not defined, then the models can't be updated later on (unless the table meta is set manually).
Parameters
- $query : mixed
- $params : mixed = []
- $options : array<string|int, mixed> = []
Return values
array<string|int, mixed> —rollback()
If not frozen, rollback transaction
public
rollback() : void
Return values
void —tableExists()
Check if a table exists via query
public
tableExists(string $name) : bool
Parameters
- $name : string
Return values
bool —unusedChildsQuery()
Query used to delet unused childs in 'Has' or 'HasAndBelongs' relations
public
unusedChildsQuery(Relation $relation, Flex $model, mixed $ids) : bool
Parameters
Return values
bool —update()
Query to update a model
public
update(mixed $model, mixed $table, mixed $updates, mixed $data, mixed $values) : bool
Parameters
- $model : mixed
- $table : mixed
- $updates : mixed
- $data : mixed
- $values : mixed
Return values
bool —updateTableTypes()
Update field types on the model table
public
updateTableTypes(Flex $model, mixed $tableFields) : void
Parameters
- $model : Flex
- $tableFields : mixed