tflori/orm

just another orm...

View the Project on GitHub tflori/orm

Build Status Test Coverage Maintainability Latest Stable Version Total Downloads

» API Reference » ORM\Dbal\Mysql

ORM\Dbal\Mysql

Table of Contents

Abstract

Extends: ORM\Dbal\Dbal

Database abstraction for MySQL databases

Methods

ORM\Dbal\Mysql::__construct

public function __construct(
    \ORM\EntityManager $entityManager, 
    array $options = [], 
)
Dbal constructor.
Parameters
Parameter Type Description
$entityManager ORM\EntityManager  
$options array  

ORM\Dbal\Mysql::__construct

↑ top


ORM\Dbal\Mysql::beginTransaction

public function beginTransaction(): bool
Begin a transaction or create a savepoint
Returns bool  

ORM\Dbal\Mysql::beginTransaction

↑ top


ORM\Dbal\Mysql::buildCompositeInExpression

public function buildCompositeInExpression(
    array $cols, 
    array $values, 
    bool $inverse = false, 
): string
Build a where in expression for composite values
Returns string  
Parameters
Parameter Type Description
$cols array  
$values array  
$inverse bool Whether it should be a IN or NOT IN operator

ORM\Dbal\Mysql::buildCompositeInExpression

↑ top


ORM\Dbal\Mysql::commit

public function commit(bool $all = false): bool
Commit the current transaction or decrease the savepoint counter

Actually nothing will be committed if there are savepoints. Instead the counter will be decreased and the commited savepoint will still be rolled back when you call rollback afterwards.

Hopefully that gives a hint why save points are no transactions and what the limitations are.

Begin transaction
  updates / inserts for transaction1
  Create savepoint transaction1
    updates / inserts for transaction2
    Create savepoint transaction2
      updates / inserts for transaction3
    <no commit here but you called commit for transaction3>
    updates / inserts for transaction2
  rollback of transaction2 to savepoint of transaction1
  update / inserts for transaction1
commit of transaction1
Returns bool  
Parameters
Parameter Type Description
$all bool Commit all opened transactions and savepoints

ORM\Dbal\Mysql::commit

↑ top


ORM\Dbal\Mysql::delete

public function delete(string $table, array $where): int
Delete rows from $table using $where conditions

Where conditions can be an array of key => value pairs to check for equality or an array of expressions.

Examples: $dbal->delete('someTable', ['id' => 23]) $dbal->delete('user', ['name = \'john\'', 'OR email=\'john.doe@example.com\''])

Tip: Use the query builder to construct where conditions: $em->query('user')->where('name', 'john')->orWhere('email', '...')->delete();

Returns int The number of deleted rows
Parameters
Parameter Type Description
$table string The table where to delete rows
$where array An array of where conditions

ORM\Dbal\Mysql::delete

↑ top


ORM\Dbal\Mysql::deleteEntity

public function deleteEntity(\ORM\Entity $entity): bool
Delete $entity from database

This method does not delete from the map - you can still receive the entity via fetch.

Returns bool  
Parameters
Parameter Type Description
$entity ORM\Entity  

ORM\Dbal\Mysql::deleteEntity

↑ top


ORM\Dbal\Mysql::describe

public function describe(string $table): \ORM\Dbal\Table|\ORM\Dbal\Column[]
Describe a table
Returns ORM\Dbal\Table|ORM\Dbal\Column[]  
Throws ORM\Exception\UnsupportedDriver  
Throws ORM\Exception  
Parameters
Parameter Type Description
$table string  

ORM\Dbal\Mysql::describe

↑ top


ORM\Dbal\Mysql::escapeIdentifier

public function escapeIdentifier(string $identifier): string
Returns $identifier quoted for use in a sql statement
Returns string  
Parameters
Parameter Type Description
$identifier string Identifier to quote

ORM\Dbal\Mysql::escapeIdentifier

↑ top


ORM\Dbal\Mysql::escapeValue

public function escapeValue(mixed $value): string
Returns $value formatted to use in a sql statement.
Returns string  
Throws ORM\Exception\NotScalar  
Parameters
Parameter Type Description
$value mixed The variable that should be returned in SQL syntax

ORM\Dbal\Mysql::escapeValue

↑ top


ORM\Dbal\Mysql::insert

public function insert(mixed $table, array $rows): mixed
Returns mixed  
Parameters
Parameter Type Description
$table mixed  
$rows array  

ORM\Dbal\Mysql::insert

↑ top


ORM\Dbal\Mysql::insertAndSync

public function insertAndSync(\ORM\Entity $entities): bool
Insert $entities and update with default values from database

The entities have to be from same type otherwise a InvalidArgument will be thrown.

Returns bool  
Throws ORM\Exception\InvalidArgument  
Parameters
Parameter Type Description
$entities ORM\Entity  

ORM\Dbal\Mysql::insertAndSync

↑ top


ORM\Dbal\Mysql::insertAndSyncWithAutoInc

public function insertAndSyncWithAutoInc(\ORM\Entity $entities): int|bool
Insert $entities and sync with auto increment primary key

The entities have to be from same type otherwise a InvalidArgument will be thrown.

Returns int|bool  
Throws ORM\Exception\UnsupportedDriver  
Throws ORM\Exception\InvalidArgument  
Parameters
Parameter Type Description
$entities ORM\Entity  

ORM\Dbal\Mysql::insertAndSyncWithAutoInc

↑ top


ORM\Dbal\Mysql::insertEntities

public function insertEntities(\ORM\Entity $entities): bool
Insert $entities into database

The entities have to be from same type otherwise a InvalidArgument will be thrown.

Returns bool  
Parameters
Parameter Type Description
$entities ORM\Entity  

ORM\Dbal\Mysql::insertEntities

↑ top


ORM\Dbal\Mysql::rollback

public function rollback(): bool
Rollback the current transaction or save point
Returns bool  

ORM\Dbal\Mysql::rollback

↑ top


ORM\Dbal\Mysql::setOption

public function setOption(string $option, mixed $value): $this
Set $option to $value
Returns $this  
Parameters
Parameter Type Description
$option string  
$value mixed  

ORM\Dbal\Mysql::setOption

↑ top


ORM\Dbal\Mysql::update

public function update(
    string $table, 
    array $where, 
    array $updates, 
    array $joins = [], 
): int
Update $table using $where to set $updates

Simple usage: update('table', ['id' => 23], ['name' => 'John Doe'])

For advanced queries with parenthesis, joins (if supported from your DBMS) etc. use QueryBuilder:

$em->query('table')
 ->where('birth_date', '>', EM::raw('DATE_SUB(NOW(), INTERVAL 18 YEARS)'))
 ->update(['teenager' => true]);
Returns int The number of affected rows
Throws ORM\Exception\UnsupportedDriver  
Parameters
Parameter Type Description
$table string The table to update
$where array An array of where conditions
$updates array An array of columns to update
$joins array For internal use from query builder only

ORM\Dbal\Mysql::update

↑ top