Skip to content

Phalcon Datamapper

Updated View as Markdown

DataMapper\Pdo\Connection

ClassSource on GitHub

Provides array quoting, profiling, a new perform() method, new fetch*() methods

Uses Phalcon\DataMapper\Pdo\Connection\AbstractConnection · Phalcon\DataMapper\Pdo\Exception\DriverNotSupported · Phalcon\DataMapper\Pdo\Profiler\Profiler · Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface

Method Summary

Properties

protectedarray$arguments = []

Methods

Public · 4

__construct()

public function __construct(
    string $dsn,
    string|null $username = null,
    string|null $password = null,
    array $options = [],
    array $queries = [],
    ProfilerInterface|null $profiler = null
);

Constructor.

This overrides the parent so that it can take connection attributes as a constructor parameter, and set them after connection.

__debugInfo()

public function __debugInfo(): array;

The purpose of this method is to hide sensitive data from stack traces.

connect()

public function connect(): void;

Connects to the database.

disconnect()

public function disconnect(): void;

Disconnects from the database.

DataMapper\Pdo\ConnectionLocator

ClassSource on GitHub

Manages Connection instances for default, read, and write connections.

The locator gives its events manager to each connection that it returns, so connections that are built on demand also fire the DataMapper events.

Uses Phalcon\Contracts\Events\EventsAware · Phalcon\DataMapper\Pdo\Connection\ConnectionInterface · Phalcon\DataMapper\Pdo\Exception\ConnectionNotFound · Phalcon\Events\ManagerInterface · Phalcon\Events\Traits\EventsAwareTrait

Method Summary

Properties

protectedConnectionInterface$masterA default Connection connection factory/instance.
protectedarray$read = []A registry of Connection "read" factories/instances.
protectedarray$write = []A registry of Connection "write" factories/instances.

Methods

Public · 7

__construct()

public function __construct(
    ConnectionInterface $master,
    array $read = [],
    array $write = []
);

Constructor.

getMaster()

public function getMaster(): ConnectionInterface;

Returns the default connection object.

getRead()

public function getRead( string $name = "" ): ConnectionInterface;

Returns a read connection by name; if no name is given, picks a random connection; if no read connections are present, returns the default connection.

getWrite()

public function getWrite( string $name = "" ): ConnectionInterface;

Returns a write connection by name; if no name is given, picks a random connection; if no write connections are present, returns the default connection.

setMaster()

public function setMaster( ConnectionInterface $callableObject ): static;

Sets the default connection factory.

setRead()

public function setRead(
    string $name,
    callable $callableObject
): static;

Sets a read connection factory by name.

setWrite()

public function setWrite(
    string $name,
    callable $callableObject
): static;

Sets a write connection factory by name.

Protected · 1

getConnection()

protected function getConnection(
    string $type,
    string $name = ""
): ConnectionInterface;

Returns a connection by name.

DataMapper\Pdo\ConnectionLocatorInterface

InterfaceSource on GitHub

Locates PDO connections for default, read, and write databases.

  • Phalcon\DataMapper\Pdo\ConnectionLocatorInterface

Uses Phalcon\DataMapper\Pdo\Connection\ConnectionInterface

Method Summary

Methods

Public · 6

getMaster()

public function getMaster(): ConnectionInterface;

Returns the default connection object.

getRead()

public function getRead( string $name = "" ): ConnectionInterface;

Returns a read connection by name; if no name is given, picks a random connection; if no read connections are present, returns the default connection.

getWrite()

public function getWrite( string $name = "" ): ConnectionInterface;

Returns a write connection by name; if no name is given, picks a random connection; if no write connections are present, returns the default connection.

setMaster()

public function setMaster( ConnectionInterface $callableObject ): ConnectionLocatorInterface;

Sets the default connection registry entry.

setRead()

public function setRead(
    string $name,
    callable $callableObject
): ConnectionLocatorInterface;

Sets a read connection registry entry by name.

setWrite()

public function setWrite(
    string $name,
    callable $callableObject
): ConnectionLocatorInterface;

Sets a write connection registry entry by name.

DataMapper\Pdo\Connection\AbstractConnection

AbstractSource on GitHub

Provides array quoting, profiling, a new perform() method, new fetch*() methods

Connections fire the lifecycle events in Phalcon\DataMapper\Pdo\Events when an events manager is set. ConnectionInterface does not declare the events manager methods; the EventsAware contract is applied here so that existing implementations of the interface keep working.

Uses BadMethodCallException · Phalcon\Contracts\Events\EventsAware · Phalcon\DataMapper\Pdo\Events · Phalcon\DataMapper\Pdo\Exception\OperationCancelled · Phalcon\DataMapper\Pdo\Exception\UnknownDriverMethod · Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface · Phalcon\Events\ManagerInterface · Phalcon\Events\Traits\EventsAwareTrait

Method Summary

public__call(mixed$name,array$arguments)Proxies to PDO methods created for specific drivers; in particular,publicboolbeginTransaction()Begins a transaction. If the profiler is enabled, the operation willpublicboolcommit()Commits the existing transaction. If the profiler is enabled, thepublicvoidconnect()Connects to the database.publicvoiddisconnect()Disconnects from the database.publicvoidensureConnection()Ensures the connection is alive, reconnecting in place if it is not.publicstring|nullerrorCode()Gets the most recent error code.publicarrayerrorInfo()Gets the most recent error info.publicintexec( string$statement )Executes an SQL statement and returns the number of affected rows. IfpublicintfetchAffected(string$statement,array$values = [])Performs a statement and returns the number of affected rows.publicarrayfetchAll(string$statement,array$values = [])Fetches a sequential array of rows from the database; the rows arepublicarrayfetchAssoc(string$statement,array$values = [])Fetches an associative array of rows from the database; the rows arepublicarrayfetchColumn(string$statement,array$values = [],int$column = 0)Fetches a column of rows as a sequential array (default first one).publicarrayfetchGroup(string$statement,array$values = [],int$flags = \PDO::FETCH_ASSOC)Fetches multiple from the database as an associative array. The firstpublicobjectfetchObject(string$statement,array$values = [],string$className = "stdClass",array$arguments = [])Fetches one row from the database as an object where the column valuespublicarrayfetchObjects(string$statement,array$values = [],string$className = "stdClass",array$arguments = [])Fetches a sequential array of rows from the database; the rows arepublicarrayfetchOne(string$statement,array$values = [])Fetches one row from the database as an associative array.publicarrayfetchPairs(string$statement,array$values = [])Fetches an associative array of rows as key-value pairs (first column ispublicfetchValue(string$statement,array$values = [])Fetches the very first value (i.e., first column of the first row).public\PDOgetAdapter()Return the inner PDO (if any)publicmixedgetAttribute( int$attribute )Retrieve a database connection attributepublicboolgetAutoReconnect()Returns whether transparent auto-reconnect is enabled.publicarraygetAvailableDrivers()Return an array of available PDO drivers (empty array if none available)publicstringgetDriverName()Return the driver namepublicProfilerInterfacegetProfiler()Returns the Profiler instance.publicarraygetQuoteNames( string$driver = "" )Gets the quote parameters based on the driverpublicboolinTransaction()Is a transaction currently active? If the profiler is enabled, thepublicboolisConnected()Is the PDO connection active?publicstringlastInsertId( string|null$name = null )Returns the last inserted autoincrement sequence value. If the profilerpublic\PDOStatementperform(string$statement,array$values = [])Performs a query with bound values and returns the resultingpublicboolping()Checks whether the underlying connection is still alive by issuing apublic\PDOStatement|boolprepare(string$statement,array$options = [])Prepares an SQL statement for execution.public\PDOStatement|boolquery( string$statement )Queries the database and returns a PDOStatement. If the profiler ispublicstringquote(mixed$value,int$type = \PDO::PARAM_STR)Quotes a value for use in an SQL statement. This differs frompublicboolrollBack()Rolls back the current transaction, and restores autocommit mode. If thepublicboolsetAttribute(int$attribute,mixed$value)Set a database connection attributepublicstaticsetAutoReconnect( bool$autoReconnect )Enables or disables transparent auto-reconnect on a lost connection.publicstaticsetProfiler( ProfilerInterface$profiler )Sets the Profiler instance.protectedarrayfetchData(string$method,array$arguments,string$statement,array$values = [])Helper method to get data from PDO based on the method passedprotectedvoidfireBefore(string$eventName,mixed$data = null)Fires a cancellable "before" event. A listener cancels by stopping theprotectedboolisConnectionError( \Throwable$exception )Recognizes a lost ("gone away") connection. Detection is driver-agnostic:protectedvoidperformBind(\PDOStatement$statement,mixed$name,mixed$arguments)Bind a value using the proper PDO::PARAM_* type.

Properties

protectedbool$autoReconnect = falseWhether to transparently reconnect and retry once when a statement fails because the connection was lost. Opt-in; off by default.
protected\PDO$pdo
protectedProfilerInterface$profiler
protectedint$transactionLevel = 0Current transaction nesting level. Tracked locally rather than via PDO::inTransaction() because some drivers report a broken connection as being "in transaction".

Methods

Public · 38

__call()

public function __call(
    mixed $name,
    array $arguments
);

Proxies to PDO methods created for specific drivers; in particular, sqlite and pgsql.

beginTransaction()

public function beginTransaction(): bool;

Begins a transaction. If the profiler is enabled, the operation will be recorded.

commit()

public function commit(): bool;

Commits the existing transaction. If the profiler is enabled, the operation will be recorded.

connect()

abstract public function connect(): void;

Connects to the database.

disconnect()

abstract public function disconnect(): void;

Disconnects from the database.

ensureConnection()

public function ensureConnection(): void;

Ensures the connection is alive, reconnecting in place if it is not. disconnect() is required first because connect() is idempotent and will not rebuild a dead-but-present handle.

errorCode()

public function errorCode(): string|null;

Gets the most recent error code.

errorInfo()

public function errorInfo(): array;

Gets the most recent error info.

exec()

public function exec( string $statement ): int;

Executes an SQL statement and returns the number of affected rows. If the profiler is enabled, the operation will be recorded.

fetchAffected()

public function fetchAffected(
    string $statement,
    array $values = []
): int;

Performs a statement and returns the number of affected rows.

fetchAll()

public function fetchAll(
    string $statement,
    array $values = []
): array;

Fetches a sequential array of rows from the database; the rows are returned as associative arrays.

fetchAssoc()

public function fetchAssoc(
    string $statement,
    array $values = []
): array;

Fetches an associative array of rows from the database; the rows are returned as associative arrays, and the array of rows is keyed on the first column of each row.

If multiple rows have the same first column value, the last row with that value will overwrite earlier rows. This method is more resource intensive and should be avoided if possible.

fetchColumn()

public function fetchColumn(
    string $statement,
    array $values = [],
    int $column = 0
): array;

Fetches a column of rows as a sequential array (default first one).

fetchGroup()

public function fetchGroup(
    string $statement,
    array $values = [],
    int $flags = \PDO::FETCH_ASSOC
): array;

Fetches multiple from the database as an associative array. The first column will be the index key. The default flags are PDO::FETCH_ASSOC | PDO::FETCH_GROUP

fetchObject()

public function fetchObject(
    string $statement,
    array $values = [],
    string $className = "stdClass",
    array $arguments = []
): object;

Fetches one row from the database as an object where the column values are mapped to object properties.

Since PDO injects property values before invoking the constructor, any initializations for defaults that you potentially have in your object’s constructor, will override the values that have been injected by fetchObject. The default object returned is \stdClass

fetchObjects()

public function fetchObjects(
    string $statement,
    array $values = [],
    string $className = "stdClass",
    array $arguments = []
): array;

Fetches a sequential array of rows from the database; the rows are returned as objects where the column values are mapped to object properties.

Since PDO injects property values before invoking the constructor, any initializations for defaults that you potentially have in your object’s constructor, will override the values that have been injected by fetchObject. The default object returned is \stdClass

fetchOne()

public function fetchOne(
    string $statement,
    array $values = []
): array;

Fetches one row from the database as an associative array.

fetchPairs()

public function fetchPairs(
    string $statement,
    array $values = []
): array;

Fetches an associative array of rows as key-value pairs (first column is the key, second column is the value).

fetchValue()

public function fetchValue(
    string $statement,
    array $values = []
);

Fetches the very first value (i.e., first column of the first row).

getAdapter()

public function getAdapter(): \PDO;

Return the inner PDO (if any)

getAttribute()

public function getAttribute( int $attribute ): mixed;

Retrieve a database connection attribute

getAutoReconnect()

public function getAutoReconnect(): bool;

Returns whether transparent auto-reconnect is enabled.

getAvailableDrivers()

public static function getAvailableDrivers(): array;

Return an array of available PDO drivers (empty array if none available)

getDriverName()

public function getDriverName(): string;

Return the driver name

getProfiler()

public function getProfiler(): ProfilerInterface;

Returns the Profiler instance.

getQuoteNames()

public function getQuoteNames( string $driver = "" ): array;

Gets the quote parameters based on the driver

inTransaction()

public function inTransaction(): bool;

Is a transaction currently active? If the profiler is enabled, the operation will be recorded. If the profiler is enabled, the operation will be recorded.

isConnected()

public function isConnected(): bool;

Is the PDO connection active?

lastInsertId()

public function lastInsertId( string|null $name = null ): string;

Returns the last inserted autoincrement sequence value. If the profiler is enabled, the operation will be recorded.

perform()

public function perform(
    string $statement,
    array $values = []
): \PDOStatement;

Performs a query with bound values and returns the resulting PDOStatement; array values will be passed through quote() and their respective placeholders will be replaced in the query string. If the profiler is enabled, the operation will be recorded.

ping()

public function ping(): bool;

Checks whether the underlying connection is still alive by issuing a trivial query. Returns false if there is no handle or the probe fails.

prepare()

public function prepare(
    string $statement,
    array $options = []
): \PDOStatement|bool;

Prepares an SQL statement for execution.

query()

public function query( string $statement ): \PDOStatement|bool;

Queries the database and returns a PDOStatement. If the profiler is enabled, the operation will be recorded.

quote()

public function quote(
    mixed $value,
    int $type = \PDO::PARAM_STR
): string;

Quotes a value for use in an SQL statement. This differs from PDO::quote() in that it will convert an array into a string of comma-separated quoted values. The default type is PDO::PARAM_STR

rollBack()

public function rollBack(): bool;

Rolls back the current transaction, and restores autocommit mode. If the profiler is enabled, the operation will be recorded.

setAttribute()

public function setAttribute(
    int $attribute,
    mixed $value
): bool;

Set a database connection attribute

setAutoReconnect()

public function setAutoReconnect( bool $autoReconnect ): static;

Enables or disables transparent auto-reconnect on a lost connection.

setProfiler()

public function setProfiler( ProfilerInterface $profiler ): static;

Sets the Profiler instance.

Protected · 4

fetchData()

protected function fetchData(
    string $method,
    array $arguments,
    string $statement,
    array $values = []
): array;

Helper method to get data from PDO based on the method passed

fireBefore()

protected function fireBefore(
    string $eventName,
    mixed $data = null
): void;

Fires a cancellable “before” event. A listener cancels by stopping the event and returning false; see Phalcon\DataMapper\Pdo\Events for the required idiom. The operation does not run when it is cancelled.

isConnectionError()

protected function isConnectionError( \Throwable $exception ): bool;

Recognizes a lost (“gone away”) connection. Detection is driver-agnostic: the driver name is not queried because the underlying connection may be dead by this point. The MySQL error codes and PostgreSQL SQLSTATEs do not overlap, so all known signatures are checked unconditionally.

performBind()

protected function performBind(
    \PDOStatement $statement,
    mixed $name,
    mixed $arguments
): void;

Bind a value using the proper PDO::PARAM_* type.

DataMapper\Pdo\Connection\ConnectionInterface

InterfaceSource on GitHub

Provides array quoting, profiling, a new perform() method, new fetch*() methods

Uses Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface

Method Summary

publicvoidconnect()Connects to the database.publicvoiddisconnect()Disconnects from the database.publicintfetchAffected(string$statement,array$values = [])Performs a statement and returns the number of affected rows.publicarrayfetchAll(string$statement,array$values = [])Fetches a sequential array of rows from the database; the rows arepublicarrayfetchAssoc(string$statement,array$values = [])Fetches an associative array of rows from the database; the rows arepublicarrayfetchColumn(string$statement,array$values = [],int$column = 0)Fetches a column of rows as a sequential array (default first one).publicarrayfetchGroup(string$statement,array$values = [],int$flags = \PDO::FETCH_ASSOC)Fetches multiple from the database as an associative array. The firstpublicobjectfetchObject(string$statement,array$values = [],string$className = "stdClass",array$arguments = [])Fetches one row from the database as an object where the column valuespublicarrayfetchObjects(string$statement,array$values = [],string$className = "stdClass",array$arguments = [])Fetches a sequential array of rows from the database; the rows arepublicarrayfetchOne(string$statement,array$values = [])Fetches one row from the database as an associative array.publicarrayfetchPairs(string$statement,array$values = [])Fetches an associative array of rows as key-value pairs (first column ispublicmixedfetchValue(string$statement,array$values = [])Fetches the very first value (i.e., first column of the first row).public\PDOgetAdapter()Return the inner PDO (if any)publicProfilerInterfacegetProfiler()Returns the Profiler instance.publicboolisConnected()Is the PDO connection active?public\PDOStatementperform(string$statement,array$values = [])Performs a query with bound values and returns the resultingpublicsetProfiler( ProfilerInterface$profiler )Sets the Profiler instance.

Methods

Public · 17

connect()

public function connect(): void;

Connects to the database.

disconnect()

public function disconnect(): void;

Disconnects from the database.

fetchAffected()

public function fetchAffected(
    string $statement,
    array $values = []
): int;

Performs a statement and returns the number of affected rows.

fetchAll()

public function fetchAll(
    string $statement,
    array $values = []
): array;

Fetches a sequential array of rows from the database; the rows are returned as associative arrays.

fetchAssoc()

public function fetchAssoc(
    string $statement,
    array $values = []
): array;

Fetches an associative array of rows from the database; the rows are returned as associative arrays, and the array of rows is keyed on the first column of each row.

If multiple rows have the same first column value, the last row with that value will overwrite earlier rows. This method is more resource intensive and should be avoided if possible.

fetchColumn()

public function fetchColumn(
    string $statement,
    array $values = [],
    int $column = 0
): array;

Fetches a column of rows as a sequential array (default first one).

fetchGroup()

public function fetchGroup(
    string $statement,
    array $values = [],
    int $flags = \PDO::FETCH_ASSOC
): array;

Fetches multiple from the database as an associative array. The first column will be the index key. The default flags are PDO::FETCH_ASSOC | PDO::FETCH_GROUP

fetchObject()

public function fetchObject(
    string $statement,
    array $values = [],
    string $className = "stdClass",
    array $arguments = []
): object;

Fetches one row from the database as an object where the column values are mapped to object properties.

Since PDO injects property values before invoking the constructor, any initializations for defaults that you potentially have in your object’s constructor, will override the values that have been injected by fetchObject. The default object returned is \stdClass

fetchObjects()

public function fetchObjects(
    string $statement,
    array $values = [],
    string $className = "stdClass",
    array $arguments = []
): array;

Fetches a sequential array of rows from the database; the rows are returned as objects where the column values are mapped to object properties.

Since PDO injects property values before invoking the constructor, any initializations for defaults that you potentially have in your object’s constructor, will override the values that have been injected by fetchObject. The default object returned is \stdClass

fetchOne()

public function fetchOne(
    string $statement,
    array $values = []
): array;

Fetches one row from the database as an associative array.

fetchPairs()

public function fetchPairs(
    string $statement,
    array $values = []
): array;

Fetches an associative array of rows as key-value pairs (first column is the key, second column is the value).

fetchValue()

public function fetchValue(
    string $statement,
    array $values = []
): mixed;

Fetches the very first value (i.e., first column of the first row).

getAdapter()

public function getAdapter(): \PDO;

Return the inner PDO (if any)

getProfiler()

public function getProfiler(): ProfilerInterface;

Returns the Profiler instance.

isConnected()

public function isConnected(): bool;

Is the PDO connection active?

perform()

public function perform(
    string $statement,
    array $values = []
): \PDOStatement;

Performs a query with bound values and returns the resulting PDOStatement; array values will be passed through quote() and their respective placeholders will be replaced in the query string. If the profiler is enabled, the operation will be recorded.

setProfiler()

public function setProfiler( ProfilerInterface $profiler );

Sets the Profiler instance.

DataMapper\Pdo\Connection\Decorated

ClassSource on GitHub

Decorates an existing PDO instance with the extended methods.

Uses Phalcon\DataMapper\Pdo\Exception\CannotDisconnect · Phalcon\DataMapper\Pdo\Profiler\Profiler · Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface

Method Summary

Methods

Public · 3

__construct()

public function __construct(
    \PDO $pdo,
    ProfilerInterface|null $profiler = null
);

Constructor.

This overrides the parent so that it can take an existing PDO instance and decorate it with the extended methods.

connect()

public function connect(): void;

Connects to the database.

disconnect()

public function disconnect(): void;

Disconnects from the database; disallowed with decorated PDO connections.

DataMapper\Pdo\Connection\PdoInterface

InterfaceSource on GitHub

An interface to the native PDO object.

Method Summary

Methods

Public · 14

beginTransaction()

public function beginTransaction(): bool;

Begins a transaction. If the profiler is enabled, the operation will be recorded.

commit()

public function commit(): bool;

Commits the existing transaction. If the profiler is enabled, the operation will be recorded.

errorCode()

public function errorCode(): null|string;

Gets the most recent error code.

errorInfo()

public function errorInfo(): array;

Gets the most recent error info.

exec()

public function exec( string $statement ): int;

Executes an SQL statement and returns the number of affected rows. If the profiler is enabled, the operation will be recorded.

getAttribute()

public function getAttribute( int $attribute ): mixed;

Retrieve a database connection attribute

getAvailableDrivers()

public static function getAvailableDrivers(): array;

Return an array of available PDO drivers (empty array if none available)

inTransaction()

public function inTransaction(): bool;

Is a transaction currently active? If the profiler is enabled, the operation will be recorded. If the profiler is enabled, the operation will be recorded.

lastInsertId()

public function lastInsertId( string|null $name = null ): string;

Returns the last inserted autoincrement sequence value. If the profiler is enabled, the operation will be recorded.

prepare()

public function prepare(
    string $statement,
    array $options = []
): \PDOStatement|bool;

Prepares an SQL statement for execution.

query()

public function query( string $statement ): \PDOStatement|bool;

Queries the database and returns a PDOStatement. If the profiler is enabled, the operation will be recorded.

quote()

public function quote(
    mixed $value,
    int $type = \PDO::PARAM_STR
): string;

Quotes a value for use in an SQL statement. This differs from PDO::quote() in that it will convert an array into a string of comma-separated quoted values. The default type is PDO::PARAM_STR

rollBack()

public function rollBack(): bool;

Rolls back the current transaction, and restores autocommit mode. If the profiler is enabled, the operation will be recorded.

setAttribute()

public function setAttribute(
    int $attribute,
    mixed $value
): bool;

Set a database connection attribute

DataMapper\Pdo\Events

ClassSource on GitHub

Lifecycle event names fired by the DataMapper connections through Phalcon\Events\Manager. One public constant per event.

The before* events are cancellable. To cancel an operation, a listener must stop the event and return false:

$manager->attach( Events::BEFORE_PERFORM, function ($event) { $event->stop();

return false; } );

Both parts are necessary. stop() alone abandons the queue but returns the listener’s own value, which the connection cannot tell apart from “no listeners”. return false alone is replaced by any later non-null return while the manager’s stopOnFalse mode is off, which is the default. A cancelled operation throws Phalcon\DataMapper\Pdo\Exception\OperationCancelled.

The after* events are not cancellable. The operation is complete when they fire.

There are two groups of events. The operation events - perform, exec, query and the three transaction events - belong to one operation each. prepare() has no operation events because perform() calls it, and nested events for one logical operation give listeners two counts of the same work. The connection events - connect, disconnect and connectionLost

  • report a change of the connection state. They fire each time the state changes, whichever method causes it. An automatic reconnect from any method therefore reports the lost connection and the new one.
  • Phalcon\DataMapper\Pdo\Events

Constants

stringAFTER_BEGIN_TRANSACTION = "dm:afterBeginTransaction"
stringAFTER_COMMIT = "dm:afterCommit"
stringAFTER_CONNECT = "dm:afterConnect"
stringAFTER_DISCONNECT = "dm:afterDisconnect"
stringAFTER_EXEC = "dm:afterExec"
stringAFTER_PERFORM = "dm:afterPerform"
stringAFTER_QUERY = "dm:afterQuery"
stringAFTER_ROLLBACK = "dm:afterRollBack"
stringBEFORE_BEGIN_TRANSACTION = "dm:beforeBeginTransaction"
stringBEFORE_COMMIT = "dm:beforeCommit"
stringBEFORE_CONNECT = "dm:beforeConnect"
stringBEFORE_DISCONNECT = "dm:beforeDisconnect"
stringBEFORE_EXEC = "dm:beforeExec"
stringBEFORE_PERFORM = "dm:beforePerform"
stringBEFORE_QUERY = "dm:beforeQuery"
stringBEFORE_ROLLBACK = "dm:beforeRollBack"
stringCONNECTION_LOST = "dm:connectionLost"

DataMapper\Pdo\Exception\CannotDisconnect

ClassSource on GitHub

ExtendedPdo could not disconnect; e.g., because its PDO connection was created externally and then injected.

DataMapper\Pdo\Exception\ConnectionNotFound

ClassSource on GitHub

Locator could not find a named connection.

DataMapper\Pdo\Exception\DriverNotSupported

ClassSource on GitHub
  • \InvalidArgumentException
    • Phalcon\DataMapper\Pdo\Exception\DriverNotSupported

Uses InvalidArgumentException

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $driver );

DataMapper\Pdo\Exception\Exception

ClassSource on GitHub

Base Exception class

DataMapper\Pdo\Exception\OperationCancelled

ClassSource on GitHub

A listener cancelled a cancellable “before” event, so the operation did not run. This is a deliberate cancellation, not a database failure. Catch this class to tell the two apart.

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $eventName );

DataMapper\Pdo\Exception\UnknownDriverMethod

ClassSource on GitHub
  • \BadMethodCallException
    • Phalcon\DataMapper\Pdo\Exception\UnknownDriverMethod

Uses BadMethodCallException

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $message );

DataMapper\Pdo\Exception\UnknownQueryMethod

ClassSource on GitHub
  • \BadMethodCallException
    • Phalcon\DataMapper\Pdo\Exception\UnknownQueryMethod

Uses BadMethodCallException

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $method );

DataMapper\Pdo\Profiler\MemoryLogger

ClassSource on GitHub

A memory-based logger.

Uses Phalcon\Logger\Adapter\AdapterInterface · Phalcon\Logger\Adapter\Noop · Phalcon\Logger\Enum · Phalcon\Logger\LoggerInterface

Method Summary

Properties

protectedarray$messages = []

Methods

Public · 15

alert()

public function alert(
    string $message,
    array $context = []
): void;

critical()

public function critical(
    string $message,
    array $context = []
): void;

debug()

public function debug(
    string $message,
    array $context = []
): void;

emergency()

public function emergency(
    string $message,
    array $context = []
): void;

error()

public function error(
    string $message,
    array $context = []
): void;

getAdapter()

public function getAdapter( string $name ): AdapterInterface;

Returns an adapter from the stack

getAdapters()

public function getAdapters(): array;

Returns the adapter stack array

getLogLevel()

public function getLogLevel(): int;

Returns the log level

getMessages()

public function getMessages(): array;

Returns the logged messages.

getName()

public function getName(): string;

Returns the name of the logger

info()

public function info(
    string $message,
    array $context = []
): void;

log()

public function log(
    mixed $level,
    string $message,
    array $context = []
): void;

Logs a message.

notice()

public function notice(
    string $message,
    array $context = []
): void;

trace()

public function trace(
    string $message,
    array $context = []
): void;

warning()

public function warning(
    string $message,
    array $context = []
): void;

DataMapper\Pdo\Profiler\Profiler

ClassSource on GitHub

Sends query profiles to a logger.

Uses Phalcon\DataMapper\Pdo\Exception\Exception · Phalcon\Logger\Enum · Phalcon\Logger\LoggerInterface · Phalcon\Support\Helper\Json\Encode

Method Summary

Properties

protectedbool$active = false
protectedarray$context = []
protectedstring$logFormat = ""
protectedint|string$logLevel = 0
protectedLoggerInterface$logger

Methods

Public · 10

__construct()

public function __construct( LoggerInterface|null $logger = null );

Constructor.

finish()

public function finish(
    string|null $statement = null,
    array $values = []
): void;

Finishes and logs a profile entry.

getLogFormat()

public function getLogFormat(): string;

Returns the log message format string, with placeholders.

getLogLevel()

public function getLogLevel(): string;

Returns the level at which to log profile messages.

getLogger()

public function getLogger(): LoggerInterface;

Returns the underlying logger instance.

isActive()

public function isActive(): bool;

Returns true if logging is active.

setActive()

public function setActive( bool $active ): ProfilerInterface;

Enable or disable profiler logging.

setLogFormat()

public function setLogFormat( string $logFormat ): ProfilerInterface;

Sets the log message format string, with placeholders.

setLogLevel()

public function setLogLevel( string $logLevel ): ProfilerInterface;

Level at which to log profile messages.

start()

public function start( string $method ): void;

Starts a profile entry.

DataMapper\Pdo\Profiler\ProfilerInterface

InterfaceSource on GitHub

Interface to send query profiles to a logger.

  • Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface

Uses Phalcon\Logger\LoggerInterface

Method Summary

Methods

Public · 9

finish()

public function finish(
    string|null $statement = null,
    array $values = []
): void;

Finishes and logs a profile entry.

getLogFormat()

public function getLogFormat(): string;

Returns the log message format string, with placeholders.

getLogLevel()

public function getLogLevel(): string;

Returns the level at which to log profile messages.

getLogger()

public function getLogger(): LoggerInterface;

Returns the underlying logger instance.

isActive()

public function isActive(): bool;

Returns true if logging is active.

setActive()

public function setActive( bool $active ): ProfilerInterface;

Enable or disable profiler logging.

setLogFormat()

public function setLogFormat( string $logFormat ): ProfilerInterface;

Sets the log message format string, with placeholders.

setLogLevel()

public function setLogLevel( string $logLevel ): ProfilerInterface;

Level at which to log profile messages.

start()

public function start( string $method ): void;

Starts a profile entry.

DataMapper\Query\AbstractConditions

AbstractSource on GitHub

Class AbstractConditions

Method Summary

Methods

Public · 8

andWhere()

public function andWhere(
    string $condition,
    mixed $value = null,
    int $type = -1
): AbstractConditions;

Sets a AND for a WHERE condition

appendWhere()

public function appendWhere(
    string $condition,
    mixed $value = null,
    int $type = -1
): AbstractConditions;

Concatenates to the most recent WHERE clause

limit()

public function limit( int $limit ): AbstractConditions;

Sets the LIMIT clause

offset()

public function offset( int $offset ): AbstractConditions;

Sets the OFFSET clause

orWhere()

public function orWhere(
    string $condition,
    mixed $value = null,
    int $type = -1
): AbstractConditions;

Sets a OR for a WHERE condition

orderBy()

public function orderBy( mixed $orderBy ): AbstractConditions;

Sets the ORDER BY

where()

public function where(
    string $condition,
    mixed $value = null,
    int $type = -1
): AbstractConditions;

Sets a WHERE condition

whereEquals()

public function whereEquals( array $columnsValues ): AbstractConditions;
Protected · 9

addCondition()

protected function addCondition(
    string $store,
    string $andor,
    string $condition,
    mixed $value = null,
    int $type = -1
): void;

Appends a conditional

appendCondition()

protected function appendCondition(
    string $store,
    string $condition,
    mixed $value = null,
    int $type = -1
): void;

Concatenates a conditional

buildBy()

protected function buildBy( string $type ): string;

Builds a BY list

buildCondition()

protected function buildCondition( string $type ): string;

Builds the conditional string

buildLimit()

protected function buildLimit(): string;

Builds the LIMIT clause

buildLimitCommon()

protected function buildLimitCommon(): string;

Builds the LIMIT clause for all drivers

buildLimitEarly()

protected function buildLimitEarly(): string;

Builds the early LIMIT clause - MS SQLServer

buildLimitSqlsrv()

protected function buildLimitSqlsrv(): string;

Builds the LIMIT clause for MSSQLServer

processValue()

protected function processValue(
    string $store,
    mixed $data
): void;

Processes a value (array or string) and merges it with the store

DataMapper\Query\AbstractQuery

AbstractSource on GitHub

Class AbstractQuery

Uses Phalcon\DataMapper\Pdo\Connection

Method Summary

Properties

protectedBind$bind
protectedConnection$connection
protectedarray$store = []

Methods

Public · 18

__construct()

public function __construct(
    Connection $connection,
    Bind $bind
);

AbstractQuery constructor.

bindInline()

public function bindInline(
    mixed $value,
    int $type = -1
): string;

Binds a value inline

bindValue()

public function bindValue(
    string $key,
    mixed $value,
    int $type = -1
): AbstractQuery;

Binds a value - auto-detects the type if necessary

bindValues()

public function bindValues( array $values ): AbstractQuery;

Binds an array of values

getBindValues()

public function getBindValues(): array;

Returns all the bound values

getStatement()

abstract public function getStatement(): string;

Return the generated statement

perform()

public function perform();

Performs a statement in the connection

quoteIdentifier()

public function quoteIdentifier(
    string $name,
    int $type = \PDO::PARAM_STR
): string;

Quotes the identifier

reset()

public function reset(): void;

Resets the internal array

resetColumns()

public function resetColumns(): void;

Resets the columns

resetFlags()

public function resetFlags(): void;

Resets the flags

resetFrom()

public function resetFrom(): void;

Resets the from

resetGroupBy()

public function resetGroupBy(): void;

Resets the group by

resetHaving()

public function resetHaving(): void;

Resets the having

resetLimit()

public function resetLimit(): void;

Resets the limit and offset

resetOrderBy()

public function resetOrderBy(): void;

Resets the order by

resetWhere()

public function resetWhere(): void;

Resets the where

setFlag()

public function setFlag(
    string $flag,
    bool $enable = true
): void;

Sets a flag for the query such as “DISTINCT”

Protected · 3

buildFlags()

protected function buildFlags();

Builds the flags statement(s)

buildReturning()

protected function buildReturning(): string;

Builds the RETURNING clause

indent()

protected function indent(
    array $collection,
    string $glue = ""
): string;

Indents a collection

DataMapper\Query\Bind

ClassSource on GitHub

Class Bind

  • Phalcon\DataMapper\Query\Bind

Method Summary

Properties

protectedint$inlineCount = 0
protectedarray$store = []

Methods

Public · 5

bindInline()

public function bindInline(
    mixed $value,
    int $type = -1
): string;

remove()

public function remove( string $key ): void;

Removes a value from the store

setValue()

public function setValue(
    string $key,
    mixed $value,
    int $type = -1
): void;

Sets a value

setValues()

public function setValues(
    array $values,
    int $type = -1
): void;

Sets values from an array

toArray()

public function toArray(): array;

Returns the internal collection

Protected · 2

getType()

protected function getType( mixed $value ): int;

Auto detects the PDO type

inlineArray()

protected function inlineArray(
    array $data,
    int $type
): string;

Processes an array - if passed as an inline parameter

DataMapper\Query\Delete

ClassSource on GitHub

Delete Query

Uses Phalcon\DataMapper\Pdo\Connection

Method Summary

Methods

Public · 5

__construct()

public function __construct(
    Connection $connection,
    Bind $bind
);

Delete constructor.

from()

public function from( string $table ): Delete;

Adds table(s) in the query

getStatement()

public function getStatement(): string;

reset()

public function reset(): void;

Resets the internal store

returning()

public function returning( array $columns ): Delete;

Adds the RETURNING clause

DataMapper\Query\Insert

ClassSource on GitHub

Insert Query

Uses Phalcon\DataMapper\Pdo\Connection

Method Summary

Methods

Public · 9

__construct()

public function __construct(
    Connection $connection,
    Bind $bind
);

Insert constructor.

column()

public function column(
    string $column,
    mixed $value = null,
    int $type = -1
): Insert;

Sets a column for the INSERT query

columns()

public function columns( array $columns ): Insert;

Mass sets columns and values for the INSERT

getLastInsertId()

public function getLastInsertId( string|null $name = null ): string;

Returns the id of the last inserted record

getStatement()

public function getStatement(): string;

into()

public function into( string $table ): Insert;

Adds table(s) in the query

reset()

public function reset(): void;

Resets the internal store

returning()

public function returning( array $columns ): Insert;

Adds the RETURNING clause

set()

public function set(
    string $column,
    mixed $value = null
): Insert;

Sets a column = value condition

DataMapper\Query\QueryFactory

ClassSource on GitHub

QueryFactory

  • Phalcon\DataMapper\Query\QueryFactory

Uses Phalcon\DataMapper\Pdo\Connection

Method Summary

Properties

protectedstring$selectClass = ""

Methods

Public · 6

__construct()

public function __construct( string $selectClass = "" );

QueryFactory constructor.

newBind()

public function newBind(): Bind;

Create a new Bind object

newDelete()

public function newDelete( Connection $connection ): Delete;

Create a new Delete object

newInsert()

public function newInsert( Connection $connection ): Insert;

Create a new Insert object

newSelect()

public function newSelect( Connection $connection ): Select;

Create a new Select object

newUpdate()

public function newUpdate( Connection $connection ): Update;

Create a new Update object

DataMapper\Query\Select

ClassSource on GitHub

Select Query

Uses BadMethodCallException · Phalcon\DataMapper\Pdo\Exception\UnknownQueryMethod

Method Summary

public__call(string$method,array$params)Proxied methods to the connectionpublicSelectandHaving(string$condition,mixed$value = null,int$type = -1)Sets a AND for a HAVING conditionpublicSelectappendHaving(string$condition,mixed$value = null,int$type = -1)Concatenates to the most recent HAVING clausepublicSelectappendJoin(string$condition,mixed$value = null,int$type = -1)Concatenates to the most recent JOIN clausepublicSelectasAlias( string$asAlias )The AS statement for the query - useful in sub-queriespublicSelectcolumns( array$columns )The columns to select from. If a key is set in the array element, thepublicSelectdistinct( bool$enable = true )publicSelectforUpdate( bool$enable = true )Enable the FOR UPDATE for the querypublicSelectfrom( string$table )Adds table(s) in the querypublicstringgetStatement()Returns the compiled SQL statementpublicSelectgroupBy( mixed$groupBy )Sets the GROUP BYpublicboolhasColumns()Whether the query has columns or notpublicSelecthaving(string$condition,mixed$value = null,int$type = -1)Sets a HAVING conditionpublicSelectjoin(string$join,string$table,string$condition,mixed$value = null,int$type = -1)Sets a 'JOIN' conditionpublicSelectorHaving(string$condition,mixed$value = null,int$type = -1)Sets a OR for a HAVING conditionpublicvoidreset()Resets the internal collectionspublicSelectsubSelect()Start a sub-selectpublicSelectunion()Start a UNIONpublicSelectunionAll()Start a UNION ALLprotectedstringgetCurrentStatement( string$suffix = "" )Statement builder

Constants

stringJOIN_INNER = "INNER"
stringJOIN_LEFT = "LEFT"
stringJOIN_NATURAL = "NATURAL"
stringJOIN_RIGHT = "RIGHT"

Properties

protectedstring$asAlias = ""
protectedbool$forUpdate = false

Methods

Public · 19

__call()

public function __call(
    string $method,
    array $params
);

Proxied methods to the connection

andHaving()

public function andHaving(
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Sets a AND for a HAVING condition

appendHaving()

public function appendHaving(
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Concatenates to the most recent HAVING clause

appendJoin()

public function appendJoin(
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Concatenates to the most recent JOIN clause

asAlias()

public function asAlias( string $asAlias ): Select;

The AS statement for the query - useful in sub-queries

columns()

public function columns( array $columns ): Select;

The columns to select from. If a key is set in the array element, the key will be used as the alias

distinct()

public function distinct( bool $enable = true ): Select;

forUpdate()

public function forUpdate( bool $enable = true ): Select;

Enable the FOR UPDATE for the query

from()

public function from( string $table ): Select;

Adds table(s) in the query

getStatement()

public function getStatement(): string;

Returns the compiled SQL statement

groupBy()

public function groupBy( mixed $groupBy ): Select;

Sets the GROUP BY

hasColumns()

public function hasColumns(): bool;

Whether the query has columns or not

having()

public function having(
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Sets a HAVING condition

join()

public function join(
    string $join,
    string $table,
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Sets a ‘JOIN’ condition

orHaving()

public function orHaving(
    string $condition,
    mixed $value = null,
    int $type = -1
): Select;

Sets a OR for a HAVING condition

reset()

public function reset(): void;

Resets the internal collections

subSelect()

public function subSelect(): Select;

Start a sub-select

union()

public function union(): Select;

Start a UNION

unionAll()

public function unionAll(): Select;

Start a UNION ALL

Protected · 1

getCurrentStatement()

protected function getCurrentStatement( string $suffix = "" ): string;

Statement builder

DataMapper\Query\Update

ClassSource on GitHub

Update Query

Uses Phalcon\DataMapper\Pdo\Connection

Method Summary

Methods

Public · 9

__construct()

public function __construct(
    Connection $connection,
    Bind $bind
);

Update constructor.

column()

public function column(
    string $column,
    mixed $value = null,
    int $type = -1
): Update;

Sets a column for the UPDATE query

columns()

public function columns( array $columns ): Update;

Mass sets columns and values for the UPDATE

from()

public function from( string $table ): Update;

Adds table(s) in the query

getStatement()

public function getStatement(): string;

hasColumns()

public function hasColumns(): bool;

Whether the query has columns or not

reset()

public function reset(): void;

Resets the internal store

returning()

public function returning( array $columns ): Update;

Adds the RETURNING clause

set()

public function set(
    string $column,
    mixed $value = null
): Update;

Sets a column = value condition

Type to search…

↑↓ navigate↵ selectEsc close