Phalcon db
NOTE
All classes are prefixed with Phalcon
Db\AbstractDb¶
Abstract Source on GitHub
Phalcon\Db and its related classes provide a simple SQL database interface for Phalcon Framework. The Phalcon\Db is the basic class you use to connect your PHP application to an RDBMS. There is a different adapter class for each brand of RDBMS.
This component is intended to lower level database operations. If you want to interact with databases using higher level of abstraction use Phalcon\Mvc\Model.
Phalcon\Db\AbstractDb is an abstract class. You only can use it with a database adapter like Phalcon\Db\Adapter\Pdo
use Phalcon\Db;
use Phalcon\Db\Exception;
use Phalcon\Db\Adapter\Pdo\Mysql as MysqlConnection;
try {
$connection = new MysqlConnection(
[
"host" => "192.168.0.11",
"username" => "sigma",
"password" => "secret",
"dbname" => "blog",
"port" => "3306",
]
);
$result = $connection->query(
"SELECT * FROM co_invoices LIMIT 5"
);
$result->setFetchMode(Enum::FETCH_NUM);
while ($invoice = $result->fetch()) {
print_r($invoice);
}
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
Phalcon\Db\AbstractDb
Uses Phalcon\Support\Settings
Method Summary¶
Methods¶
setup()¶
Enables/disables options in the Database component
Db\Adapter\AbstractAdapter¶
Abstract Source on GitHub
Base class for Phalcon\Db\Adapter adapters
Phalcon\Db\Adapter\AbstractAdapter- implementsPhalcon\Db\Adapter\AdapterInterface,Phalcon\Events\EventsAwareInterface
Uses Phalcon\Db\CheckInterface · Phalcon\Db\ColumnInterface · Phalcon\Db\DialectInterface · Phalcon\Db\Enum · Phalcon\Db\Exception · Phalcon\Db\Exceptions\CannotInsertWithoutData · Phalcon\Db\Exceptions\IncompleteBindTypes · Phalcon\Db\Exceptions\InvalidDialectClass · Phalcon\Db\Exceptions\NestedTransactionChangeBlocked · Phalcon\Db\Exceptions\SavepointsNotSupported · Phalcon\Db\Exceptions\TableMustHaveColumn · Phalcon\Db\Exceptions\UpdateFieldCountMismatch · Phalcon\Db\Index · Phalcon\Db\IndexInterface · Phalcon\Db\RawValue · Phalcon\Db\Reference · Phalcon\Db\ReferenceInterface · Phalcon\Events\EventsAwareInterface · Phalcon\Events\Traits\EventsAwareTrait
Method Summary¶
public
__construct( array $descriptor )
Phalcon\Db\Adapter constructor
public
bool
addCheck(string $tableName,string $schemaName,CheckInterface $check)
Adds a CHECK constraint to a table.
public
bool
addColumn(string $tableName,string $schemaName,ColumnInterface $column)
Adds a column to a table
public
bool
addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference)
Adds a foreign key to a table
public
bool
addIndex(string $tableName,string $schemaName,IndexInterface $index)
Adds an index to a table
public
bool
addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index)
Adds a primary key to a table
public
bool
createMaterializedView(string $viewName,array $definition,string|null $schemaName = null)
Creates a materialized view (PostgreSQL only).
public
bool
createSavepoint( string $name )
Creates a new savepoint
public
bool
createTable(string $tableName,string $schemaName,array $definition)
Creates a table
public
bool
createView(string $viewName,array $definition,string|null $schemaName = null)
Creates a view
public
bool
delete(array|string $tableName,string|null $whereCondition = null,array $placeholders = [],array $dataTypes = [])
Deletes data from a table using custom RBDM SQL syntax
public
array
describeIndexes(string $tableName,string|null $schemaName = null)
Lists table indexes
public
array
describeReferences(string $tableName,string|null $schemaName = null)
Lists table references
public
bool
dropCheck(string $tableName,string $schemaName,string $checkName)
Drops a CHECK constraint from a table.
public
bool
dropColumn(string $tableName,string $schemaName,string $columnName)
Drops a column from a table
public
bool
dropForeignKey(string $tableName,string $schemaName,string $referenceName)
Drops a foreign key from a table
public
bool
dropIndex(string $tableName,string $schemaName,string $indexName)
Drop an index from a table
public
bool
dropMaterializedView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Drops a materialized view (PostgreSQL only).
public
bool
dropPrimaryKey(string $tableName,string $schemaName)
Drops a table's primary key
public
bool
dropTable(string $tableName,string|null $schemaName = null,bool $ifExists = true)
Drops a table from a schema/database
public
bool
dropView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Drops a view
public
string
escapeIdentifier( array|float|int|string $identifier )
Escapes a column/table/schema name
public
array
fetchAll(string $sqlQuery,int $fetchMode = Enum::FETCH_ASSOC,array $bindParams = [],array $bindTypes = [])
Dumps the complete result of a query into an array
public
mixed
fetchColumn(string $sqlQuery,array $placeholders = [],int|string $column = 0)
Returns the n'th field of first row in a SQL query result
public
array|bool
fetchOne(string $sqlQuery,int $fetchMode = Enum::FETCH_ASSOC,array $bindParams = [],array $bindTypes = [])
Returns the first row in a SQL query result
public
string
forUpdate(string $sqlQuery,string $modifier = "")
Returns a SQL modified with a FOR UPDATE clause
public
string
getColumnDefinition( ColumnInterface $column )
Returns the SQL column definition from a column
public
string
getColumnList( array $columnList )
Gets a list of columns
public
int
getConnectionId()
Gets the active connection unique identifier
public
RawValue
getDefaultIdValue()
Returns the default identity value to be inserted in an identity column
public
RawValue
getDefaultValue()
Returns the default value to make the RBDM use the default value declared
public
array
getDescriptor()
Return descriptor used to connect to the active database
public
DialectInterface
getDialect()
Returns internal dialect instance
public
string
getDialectType()
Name of the dialect used
public
string
getNestedTransactionSavepointName()
Returns the savepoint name to use for nested transactions
public
string
getRealSQLStatement()
Active SQL statement in the object without replace bound parameters
public
array
getSQLBindTypes()
Active SQL statement in the object
public
string
getSQLStatement()
Active SQL statement in the object
public
array
getSQLVariables()
Active SQL variables in the object
public
string
getType()
Type of database system the adapter is used for
public
bool
insert(string $tableName,array $values,array|null $fields = null,array $dataTypes = [])
Inserts data into a table using custom RDBMS SQL syntax
public
bool
insertAsDict(string $tableName,array $data,array $dataTypes = [])
Inserts data into a table using custom RBDM SQL syntax
public
bool
isNestedTransactionsWithSavepoints()
Returns if nested transactions should use savepoints
public
string
limit(string $sqlQuery,array|int $number)
Appends a LIMIT clause to $sqlQuery argument
public
array
listTables( string|null $schemaName = null )
List all tables on a database
public
array
listViews( string|null $schemaName = null )
List all views on a database
public
bool
modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface|null $currentColumn = null)
Modifies a table column based on a definition
public
string
onConflictUpdate(string $sqlQuery,array $conflictColumns,array $updateColumns)
Appends an ON CONFLICT (...) DO UPDATE SET col = excluded.col upsert
public
bool
refreshMaterializedView(string $viewName,string|null $schemaName = null,bool $concurrent = false)
Refreshes a materialized view (PostgreSQL only).
public
bool
releaseSavepoint( string $name )
Releases given savepoint
public
string
returning(string $sqlQuery,array $columns)
Appends a RETURNING clause to an INSERT/UPDATE/DELETE statement.
public
bool
rollbackSavepoint( string $name )
Rollbacks given savepoint
public
void
setDialect( DialectInterface $dialect )
Sets the dialect used to produce the SQL
public
AdapterInterface
setNestedTransactionsWithSavepoints( bool $flag )
Set if nested transactions should use savepoints
public
void
setup( array $options )
Enables/disables options in the Database component.
public
string
sharedLock(string $sqlQuery,string $modifier = "")
Returns a SQL modified with a LOCK IN SHARE MODE clause
public
bool
supportSequences()
Check whether the database system requires a sequence to produce
public
bool
supportsDefaultValue()
Check whether the database system support the DEFAULT
public
bool
tableExists(string $tableName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.table
public
array
tableOptions(string $tableName,string|null $schemaName = null)
Gets creation options from a table
public
bool
update(string $tableName,array $fields,array $values,array|string $whereCondition = [],array $dataTypes = [])
Updates data on a table using custom RBDM SQL syntax
public
bool
updateAsDict(string $tableName,array $data,array|string $whereCondition = [],array $dataTypes = [])
Updates data on a table using custom RBDM SQL syntax
public
bool
useExplicitIdValue()
Check whether the database system requires an explicit value for identity
public
bool
viewExists(string $viewName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.view
protected
void
checkSavepoints()
Check if savepoints are supported
Properties¶
protected
int
$connectionConsecutive = 0
Connection ID
protected
int
$connectionId
Active connection ID
protected
array
$descriptor = []
Descriptor used to connect to a database
protected
DialectInterface
$dialect
Dialect instance
protected
string
$dialectType
Name of the dialect used
protected
string
$realSqlStatement = ""
The real SQL statement - what was executed
protected
array
$sqlBindTypes = []
Active SQL Bind Types
protected
string
$sqlStatement
Active SQL Statement
protected
array
$sqlVariables = []
Active SQL bound parameter variables
protected
int
$transactionLevel = 0
Current transaction level
protected
bool
$transactionsWithSavepoints = false
Whether the database supports transactions with save points
protected
string
$type
Type of database system the adapter is used for
Methods¶
__construct()¶
Phalcon\Db\Adapter constructor
Note: the options key is forwarded to the static setup() method,
which writes process-global settings affecting every connection in the
process. See setup().
addCheck()¶
Adds a CHECK constraint to a table.
addColumn()¶
Adds a column to a table
addForeignKey()¶
public function addForeignKey(
string $tableName,
string $schemaName,
ReferenceInterface $reference
): bool;
Adds a foreign key to a table
addIndex()¶
Adds an index to a table
addPrimaryKey()¶
public function addPrimaryKey(
string $tableName,
string $schemaName,
IndexInterface $index
): bool;
Adds a primary key to a table
createMaterializedView()¶
public function createMaterializedView(
string $viewName,
array $definition,
string|null $schemaName = null
): bool;
Creates a materialized view (PostgreSQL only).
createSavepoint()¶
Creates a new savepoint
createTable()¶
Creates a table
createView()¶
public function createView(
string $viewName,
array $definition,
string|null $schemaName = null
): bool;
Creates a view
delete()¶
public function delete(
array|string $tableName,
string|null $whereCondition = null,
array $placeholders = [],
array $dataTypes = []
): bool;
Deletes data from a table using custom RBDM SQL syntax
// Deleting existing invoice
$success = $connection->delete(
"co_invoices",
"inv_id = 101"
);
// Next SQL sentence is generated
DELETE FROM `co_invoices` WHERE `inv_id` = 101
Warning! If $whereCondition is string it not escaped.
describeIndexes()¶
Lists table indexes
This base implementation consumes the dialect's describeIndexes() SQL
as FETCH_NUM rows by position: column index 2 is the index key name and
column index 4 is the indexed column name. A custom dialect's
describeIndexes() SQL must emit columns in that order, or a custom
adapter must override this method. All bundled adapters except PostgreSQL
override it.
describeReferences()¶
Lists table references
This base implementation consumes the dialect's describeReferences()
SQL as FETCH_NUM rows by position: index 1 is the local column, index 2
the constraint name, index 3 the referenced schema, index 4 the
referenced table, and index 5 the referenced column. A custom dialect's
describeReferences() SQL must emit columns in that order, or a custom
adapter must override this method. Every bundled adapter (MySQL,
PostgreSQL, SQLite) overrides it, so this base implementation has no
in-tree caller and effectively assumes the PostgreSQL row shape.
dropCheck()¶
Drops a CHECK constraint from a table.
dropColumn()¶
Drops a column from a table
dropForeignKey()¶
public function dropForeignKey(
string $tableName,
string $schemaName,
string $referenceName
): bool;
Drops a foreign key from a table
dropIndex()¶
Drop an index from a table
dropMaterializedView()¶
public function dropMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): bool;
Drops a materialized view (PostgreSQL only).
dropPrimaryKey()¶
Drops a table's primary key
dropTable()¶
public function dropTable(
string $tableName,
string|null $schemaName = null,
bool $ifExists = true
): bool;
Drops a table from a schema/database
dropView()¶
public function dropView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): bool;
Drops a view
escapeIdentifier()¶
Escapes a column/table/schema name
$escapedTable = $connection->escapeIdentifier(
"co_invoices"
);
$escapedTable = $connection->escapeIdentifier(
[
"store",
"co_invoices",
]
);
fetchAll()¶
public function fetchAll(
string $sqlQuery,
int $fetchMode = Enum::FETCH_ASSOC,
array $bindParams = [],
array $bindTypes = []
): array;
Dumps the complete result of a query into an array
// Getting all invoices with associative indexes only
$invoices = $connection->fetchAll(
"SELECT * FROM co_invoices",
\Phalcon\Db\Enum::FETCH_ASSOC
);
foreach ($invoices as $invoice) {
print_r($invoice);
}
// Getting all invoices whose title contains the word "Test"
$invoices = $connection->fetchAll(
"SELECT * FROM co_invoices WHERE inv_title LIKE :inv_title",
\Phalcon\Db\Enum::FETCH_ASSOC,
[
"inv_title" => "%Test%",
]
);
foreach($invoices as $invoice) {
print_r($invoice);
}
fetchColumn()¶
public function fetchColumn(
string $sqlQuery,
array $placeholders = [],
int|string $column = 0
): mixed;
Returns the n'th field of first row in a SQL query result
// Getting count of invoices
$invoicesCount = $connection->fetchColumn("SELECT count(*) FROM co_invoices");
print_r($invoicesCount);
// Getting the title of the last created invoice
$invoice = $connection->fetchColumn(
"SELECT inv_id, inv_title FROM co_invoices ORDER BY inv_created_at DESC",
1
);
print_r($invoice);
fetchOne()¶
public function fetchOne(
string $sqlQuery,
int $fetchMode = Enum::FETCH_ASSOC,
array $bindParams = [],
array $bindTypes = []
): array|bool;
Returns the first row in a SQL query result
// Getting first invoice
$invoice = $connection->fetchOne("SELECT * FROM co_invoices");
print_r($invoice);
// Getting first invoice with associative indexes only
$invoice = $connection->fetchOne(
"SELECT * FROM co_invoices",
\Phalcon\Db\Enum::FETCH_ASSOC
);
print_r($invoice);
forUpdate()¶
Returns a SQL modified with a FOR UPDATE clause
getColumnDefinition()¶
Returns the SQL column definition from a column
getColumnList()¶
Gets a list of columns
getConnectionId()¶
Gets the active connection unique identifier
getDefaultIdValue()¶
Returns the default identity value to be inserted in an identity column
// Inserting a new invoice with a valid default value for the column 'inv_id'
$success = $connection->insert(
"co_invoices",
[
$connection->getDefaultIdValue(),
"Test Invoice",
100,
],
[
"inv_id",
"inv_title",
"inv_total",
]
);
getDefaultValue()¶
Returns the default value to make the RBDM use the default value declared in the table definition
// Inserting a new invoice with a valid default value for the column 'inv_total'
$success = $connection->insert(
"co_invoices",
[
"Test Invoice",
$connection->getDefaultValue()
],
[
"inv_title",
"inv_total",
]
);
getDescriptor()¶
Return descriptor used to connect to the active database
getDialect()¶
Returns internal dialect instance
getDialectType()¶
Name of the dialect used
getNestedTransactionSavepointName()¶
Returns the savepoint name to use for nested transactions
getRealSQLStatement()¶
Active SQL statement in the object without replace bound parameters
getSQLBindTypes()¶
Active SQL statement in the object
getSQLStatement()¶
Active SQL statement in the object
getSQLVariables()¶
Active SQL variables in the object
getType()¶
Type of database system the adapter is used for
insert()¶
public function insert(
string $tableName,
array $values,
array|null $fields = null,
array $dataTypes = []
): bool;
Inserts data into a table using custom RDBMS SQL syntax
// Inserting a new invoice
$success = $connection->insert(
"co_invoices",
["Test Invoice", 100],
["inv_title", "inv_total"]
);
// Next SQL sentence is sent to the database system
INSERT INTO `co_invoices` (`inv_title`, `inv_total`) VALUES ("Test Invoice", 100);
insertAsDict()¶
Inserts data into a table using custom RBDM SQL syntax
// Inserting a new invoice
$success = $connection->insertAsDict(
"co_invoices",
[
"inv_title" => "Test Invoice",
"inv_total" => 100,
]
);
// Next SQL sentence is sent to the database system
INSERT INTO `co_invoices` (`inv_title`, `inv_total`) VALUES ("Test Invoice", 100);
isNestedTransactionsWithSavepoints()¶
Returns if nested transactions should use savepoints
limit()¶
Appends a LIMIT clause to $sqlQuery argument
listTables()¶
List all tables on a database
listViews()¶
List all views on a database
modifyColumn()¶
public function modifyColumn(
string $tableName,
string $schemaName,
ColumnInterface $column,
ColumnInterface|null $currentColumn = null
): bool;
Modifies a table column based on a definition
onConflictUpdate()¶
public function onConflictUpdate(
string $sqlQuery,
array $conflictColumns,
array $updateColumns
): string;
Appends an ON CONFLICT (...) DO UPDATE SET col = excluded.col upsert clause to the supplied INSERT statement.
refreshMaterializedView()¶
public function refreshMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $concurrent = false
): bool;
Refreshes a materialized view (PostgreSQL only).
releaseSavepoint()¶
Releases given savepoint
returning()¶
Appends a RETURNING clause to an INSERT/UPDATE/DELETE statement.
rollbackSavepoint()¶
Rollbacks given savepoint
setDialect()¶
Sets the dialect used to produce the SQL
setNestedTransactionsWithSavepoints()¶
Set if nested transactions should use savepoints
setup()¶
Enables/disables options in the Database component.
The flags are stored as process-global Phalcon\Support\Settings
(db.escape_identifiers, db.force_casting) and therefore affect every
connection in the process at once, last-writer-wins. Call this once at
bootstrap; it is not per-connection configuration. Because the
constructor calls setup() whenever a descriptor carries an options
key, constructing one adapter with options can change the SQL another,
already-configured connection generates.
sharedLock()¶
Returns a SQL modified with a LOCK IN SHARE MODE clause
supportSequences()¶
Check whether the database system requires a sequence to produce auto-numeric values
supportsDefaultValue()¶
Check whether the database system support the DEFAULT keyword (SQLite does not support it)
tableExists()¶
Generates SQL checking for the existence of a schema.table
tableOptions()¶
Gets creation options from a table
update()¶
public function update(
string $tableName,
array $fields,
array $values,
array|string $whereCondition = [],
array $dataTypes = []
): bool;
Updates data on a table using custom RBDM SQL syntax
// Updating existing invoice
$success = $connection->update(
"co_invoices",
["inv_title"],
["New Test Invoice"],
"inv_id = 101"
);
// Next SQL sentence is sent to the database system
UPDATE `co_invoices` SET `inv_title` = "New Test Invoice" WHERE inv_id = 101
// Updating existing invoice with array condition and $dataTypes
$success = $connection->update(
"co_invoices",
["inv_title"],
["New Test Invoice"],
[
"conditions" => "inv_id = ?",
"bind" => [$some_unsafe_id],
"bindTypes" => [PDO::PARAM_INT], // use only if you use
$dataTypes param
],
[
PDO::PARAM_STR
]
);
Warning! If $whereCondition is string, it is not escaped.
updateAsDict()¶
public function updateAsDict(
string $tableName,
array $data,
array|string $whereCondition = [],
array $dataTypes = []
): bool;
Updates data on a table using custom RBDM SQL syntax Another, more convenient syntax
// Updating existing invoice
$success = $connection->updateAsDict(
"co_invoices",
[
"inv_title" => "New Test Invoice",
],
"inv_id = 101"
);
// Next SQL sentence is sent to the database system
UPDATE `co_invoices` SET `inv_title` = "New Test Invoice" WHERE inv_id = 101
useExplicitIdValue()¶
Check whether the database system requires an explicit value for identity columns
viewExists()¶
Generates SQL checking for the existence of a schema.view
checkSavepoints()¶
Check if savepoints are supported
Db\Adapter\AdapterInterface¶
Interface Source on GitHub
Phalcon\Db\Adapter\AdapterInterface
Phalcon\Contracts\Db\Adapter\AdapterPhalcon\Db\Adapter\AdapterInterface
Uses Phalcon\Contracts\Db\Adapter\Adapter
Db\Adapter\PdoFactory¶
Class Source on GitHub
Phalcon\Db\Adapter\PdoFactory
Uses Exception · Phalcon\Config\ConfigInterface · Phalcon\Db\Adapter\Pdo\Mysql · Phalcon\Db\Adapter\Pdo\Postgresql · Phalcon\Db\Adapter\Pdo\Sqlite · Phalcon\Support\Exception · Phalcon\Support\Traits\ConfigTrait · Phalcon\Traits\Factory\FactoryTrait
Method Summary¶
public
__construct( array $services = [] )
Constructor.
public
AdapterInterface
load( array|ConfigInterface $config )
Factory to create an instance from a Config object
public
AdapterInterface
newInstance(string $name,array $options = [])
Create a new instance of the adapter
protected
string
getExceptionClass()
protected
array
getServices()
Returns the available adapters
Methods¶
__construct()¶
Constructor.
load()¶
Factory to create an instance from a Config object
newInstance()¶
Create a new instance of the adapter
getExceptionClass()¶
getServices()¶
Returns the available adapters
Db\Adapter\Pdo\AbstractPdo¶
Abstract Source on GitHub
Phalcon\Db\Adapter\Pdo is the Phalcon\Db that internally uses PDO to connect to a database
use Phalcon\Db\Adapter\Pdo\Mysql;
$config = [
"host" => "localhost",
"dbname" => "blog",
"port" => 3306,
"username" => "sigma",
"password" => "secret",
];
$connection = new Mysql($config);
Phalcon\Db\Adapter\AbstractAdapterPhalcon\Db\Adapter\Pdo\AbstractPdo
Uses PDO · PDOException · PDOStatement · Phalcon\Db\Adapter\AbstractAdapter · Phalcon\Db\Column · Phalcon\Db\Exception · Phalcon\Db\Exceptions\CannotPrepareStatement · Phalcon\Db\Exceptions\InvalidBindParameter · Phalcon\Db\Exceptions\MatchedParameterNotFound · Phalcon\Db\Exceptions\NoActiveTransaction · Phalcon\Db\ResultInterface · Phalcon\Db\Result\PdoResult · Phalcon\Events\Exception · Phalcon\Support\Settings · Throwable
Method Summary¶
public
__construct( array $descriptor )
Constructor for Phalcon\Db\Adapter\Pdo
public
int
affectedRows()
Returns the number of affected rows by the latest INSERT/UPDATE/DELETE
public
bool
begin( bool $nesting = true )
Starts a transaction in the connection
public
void
close()
Closes the active connection returning success. Phalcon automatically
public
bool
commit( bool $nesting = true )
Commits the active transaction in the connection
public
void
connect( array $descriptor = [] )
This method is automatically called in \Phalcon\Db\Adapter\Pdo
public
array
convertBoundParams(string $sql,array $parameters = [])
Converts bound parameters such as :name: or ?1 into PDO bind params ?
public
void
ensureConnection()
Ensures the connection is alive, reconnecting in place if it is not.
public
string
escapeString( string $input )
Escapes a value to avoid SQL injections according to the active charset
public
bool
execute(string $sqlStatement,array $bindParams = [],array $bindTypes = [])
Sends SQL statements to the database server returning the success state.
public
PDOStatement
executePrepared(PDOStatement $statement,array $placeholders,array $dataTypes = [])
Executes a prepared statement binding. This function uses integer indexes
public
bool
getAutoReconnect()
Returns whether transparent auto-reconnect is enabled.
public
array
getErrorInfo()
Return the error info, if any
public
PDO|null
getInternalHandler()
Return internal PDO handler
public
int
getTransactionLevel()
Returns the current transaction nesting level
public
bool
isUnderTransaction()
Checks whether the connection is under a transaction
public
bool|string
lastInsertId( string|null $name = null )
Returns the insert id for the auto_increment/serial column inserted in
public
bool
ping()
Checks whether the underlying connection is still alive by issuing a
public
PDOStatement
prepare( string $sqlStatement )
Returns a PDO prepared statement to be executed with 'executePrepared'
public
bool|ResultInterface
query(string $sqlStatement,array $bindParams = [],array $bindTypes = [])
Sends SQL statements to the database server returning the success state.
public
bool
rollback( bool $nesting = true )
Rollbacks the active transaction in the connection
public
static
setAutoReconnect( bool $autoReconnect )
Enables or disables transparent auto-reconnect on a lost connection.
protected
array
getDsnDefaults()
Returns PDO adapter DSN defaults as a key-value map.
protected
bool
isConnectionError( Throwable $exception )
Recognizes whether an exception represents a lost ("gone away")
protected
void
prepareRealSql(string $statement,array $parameters)
Constructs the SQL statement (with parameters)
Properties¶
protected
int
$affectedRows = 0
Last affected rows
protected
bool
$autoReconnect = false
Whether to transparently reconnect and retry once when a query fails
because the connection was lost. Opt-in; off by default.
protected
PDO|null
$pdo = null
PDO Handler
Methods¶
__construct()¶
Constructor for Phalcon\Db\Adapter\Pdo
affectedRows()¶
Returns the number of affected rows by the latest INSERT/UPDATE/DELETE executed in the database system
$connection->execute(
"DELETE FROM co_invoices"
);
echo $connection->affectedRows(), " were deleted";
begin()¶
Starts a transaction in the connection
close()¶
Closes the active connection returning success. Phalcon automatically closes and destroys active connections when the request ends
commit()¶
Commits the active transaction in the connection
connect()¶
This method is automatically called in \Phalcon\Db\Adapter\Pdo constructor.
Call it when you need to restore a database connection.
use Phalcon\Db\Adapter\Pdo\Mysql;
// Make a connection
$connection = new Mysql(
[
"host" => "localhost",
"username" => "sigma",
"password" => "secret",
"dbname" => "blog",
"port" => 3306,
]
);
// Reconnect
$connection->connect();
convertBoundParams()¶
Converts bound parameters such as :name: or ?1 into PDO bind params ?
print_r(
$connection->convertBoundParams(
"SELECT * FROM co_invoices WHERE inv_title = :inv_title:",
[
"Test Invoice",
]
)
);
ensureConnection()¶
Ensures the connection is alive, reconnecting in place if it is not.
escapeString()¶
Escapes a value to avoid SQL injections according to the active charset in the connection
execute()¶
public function execute(
string $sqlStatement,
array $bindParams = [],
array $bindTypes = []
): bool;
Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server does not return any rows
// Inserting data
$success = $connection->execute(
"INSERT INTO co_invoices VALUES (1, 'Test Invoice')"
);
$success = $connection->execute(
"INSERT INTO co_invoices VALUES (?, ?)",
[
1,
"Test Invoice",
]
);
executePrepared()¶
public function executePrepared(
PDOStatement $statement,
array $placeholders,
array $dataTypes = []
): PDOStatement;
Executes a prepared statement binding. This function uses integer indexes starting from zero
use Phalcon\Db\Column;
$statement = $db->prepare(
"SELECT * FROM co_invoices WHERE inv_title = :inv_title"
);
$result = $connection->executePrepared(
$statement,
[
"inv_title" => "Test Invoice",
],
[
"inv_title" => Column::BIND_PARAM_STR,
]
);
getAutoReconnect()¶
Returns whether transparent auto-reconnect is enabled.
getErrorInfo()¶
Return the error info, if any
getInternalHandler()¶
Return internal PDO handler
getTransactionLevel()¶
Returns the current transaction nesting level
isUnderTransaction()¶
Checks whether the connection is under a transaction
lastInsertId()¶
Returns the insert id for the auto_increment/serial column inserted in the latest executed SQL statement
// Inserting a new invoice
$success = $connection->insert(
"co_invoices",
[
"Test Invoice",
100,
],
[
"inv_title",
"inv_total",
]
);
// Getting the generated id
$id = $connection->lastInsertId();
ping()¶
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()¶
Returns a PDO prepared statement to be executed with 'executePrepared'
use Phalcon\Db\Column;
$statement = $db->prepare(
"SELECT * FROM co_invoices WHERE inv_title = :inv_title"
);
$result = $connection->executePrepared(
$statement,
[
"inv_title" => "Test Invoice",
],
[
"inv_title" => Column::BIND_PARAM_INT,
]
);
query()¶
public function query(
string $sqlStatement,
array $bindParams = [],
array $bindTypes = []
): bool|ResultInterface;
Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server is returning rows
// Querying data
$resultset = $connection->query(
"SELECT * FROM co_invoices WHERE inv_status_flag = 1"
);
$resultset = $connection->query(
"SELECT * FROM co_invoices WHERE inv_status_flag = ?",
[
1,
]
);
rollback()¶
Rollbacks the active transaction in the connection
setAutoReconnect()¶
Enables or disables transparent auto-reconnect on a lost connection.
getDsnDefaults()¶
Returns PDO adapter DSN defaults as a key-value map.
isConnectionError()¶
Recognizes whether an exception represents a lost ("gone away") connection. The base adapter cannot know driver specifics, so it returns false; concrete adapters override this.
prepareRealSql()¶
Constructs the SQL statement (with parameters)
@see https://stackoverflow.com/a/8403150
Db\Adapter\Pdo\Mysql¶
Class Source on GitHub
Specific functions for the MySQL database system
use Phalcon\Db\Adapter\Pdo\Mysql;
$config = [
"host" => "localhost",
"dbname" => "blog",
"port" => 3306,
"username" => "sigma",
"password" => "secret",
];
$connection = new Mysql($config);
Phalcon\Db\Adapter\AbstractAdapterPhalcon\Db\Adapter\Pdo\AbstractPdoPhalcon\Db\Adapter\Pdo\Mysql
Uses PDO · PDOException · Phalcon\Db\Adapter\Pdo\AbstractPdo · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Enum · Phalcon\Db\Exception · Phalcon\Db\Exceptions\MissingForeignKeyChecks · Phalcon\Db\Index · Phalcon\Db\IndexInterface · Phalcon\Db\Reference · Phalcon\Db\ReferenceInterface · Throwable
Method Summary¶
public
bool
addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference)
Adds a foreign key to a table
public
void
connect( array $descriptor = [] )
public
array
describeColumns(string $tableName,string|null $schemaName = null)
Returns an array of Phalcon\Db\Column objects describing a table
public
array
describeIndexes(string $tableName,string|null $schemaName = null)
Lists table indexes
public
array
describeReferences(string $tableName,string|null $schemaName = null)
Lists table references
protected
array
getDsnDefaults()
Returns PDO adapter DSN defaults as a key-value map.
protected
bool
isConnectionError( Throwable $exception )
Recognizes a MySQL "server has gone away" / "Lost connection" failure
Properties¶
protected
string
$dialectType = "mysql"
protected
string
$type = "mysql"
Methods¶
addForeignKey()¶
public function addForeignKey(
string $tableName,
string $schemaName,
ReferenceInterface $reference
): bool;
Adds a foreign key to a table
connect()¶
describeColumns()¶
Returns an array of Phalcon\Db\Column objects describing a table
describeIndexes()¶
Lists table indexes
describeReferences()¶
Lists table references
getDsnDefaults()¶
Returns PDO adapter DSN defaults as a key-value map.
isConnectionError()¶
Recognizes a MySQL "server has gone away" / "Lost connection" failure by the driver error code (2006 / 2013) with a message fallback.
Db\Adapter\Pdo\Postgresql¶
Class Source on GitHub
Specific functions for the PostgreSQL database system
use Phalcon\Db\Adapter\Pdo\Postgresql;
$config = [
"host" => "localhost",
"dbname" => "blog",
"port" => 5432,
"username" => "postgres",
"password" => "secret",
];
$connection = new Postgresql($config);
Phalcon\Db\Adapter\AbstractAdapterPhalcon\Db\Adapter\Pdo\AbstractPdoPhalcon\Db\Adapter\Pdo\Postgresql
Uses Phalcon\Db\Adapter\Pdo\AbstractPdo · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Enum · Phalcon\Db\Exception · Phalcon\Db\Exceptions\TableMustHaveColumn · Phalcon\Db\RawValue · Phalcon\Db\Reference · Phalcon\Db\ReferenceInterface · Throwable
Method Summary¶
public
__construct( array $descriptor )
Constructor for Phalcon\Db\Adapter\Pdo\Postgresql
public
void
connect( array $descriptor = [] )
This method is automatically called in Phalcon\Db\Adapter\Pdo
public
bool
createTable(string $tableName,string $schemaName,array $definition)
Creates a table
public
array
describeColumns(string $tableName,string|null $schemaName = null)
Returns an array of Phalcon\Db\Column objects describing a table
public
array
describeReferences(string $tableName,string|null $schemaName = null)
Lists table references
public
RawValue
getDefaultIdValue()
Returns the default identity value to be inserted in an identity column
public
bool
modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface|null $currentColumn = null)
Modifies a table column based on a $definition
public
bool
supportSequences()
Check whether the database system requires a sequence to produce
public
bool
useExplicitIdValue()
Check whether the database system requires an explicit value for identity
protected
array
getDsnDefaults()
Returns PDO adapter DSN defaults as a key-value map.
protected
bool
isConnectionError( Throwable $exception )
Recognizes a PostgreSQL connection-loss failure by SQLSTATE
Properties¶
protected
string
$dialectType = "postgresql"
protected
string
$type = "pgsql"
Methods¶
__construct()¶
Constructor for Phalcon\Db\Adapter\Pdo\Postgresql
connect()¶
This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. Call it when you need to restore a database connection.
createTable()¶
Creates a table
describeColumns()¶
Returns an array of Phalcon\Db\Column objects describing a table
describeReferences()¶
Lists table references
getDefaultIdValue()¶
Returns the default identity value to be inserted in an identity column
// Inserting a new invoice with a valid default value for the column 'inv_id'
$success = $connection->insert(
"co_invoices",
[
$connection->getDefaultIdValue(),
"Test Invoice",
100,
],
[
"inv_id",
"inv_title",
"inv_total",
]
);
modifyColumn()¶
public function modifyColumn(
string $tableName,
string $schemaName,
ColumnInterface $column,
ColumnInterface|null $currentColumn = null
): bool;
Modifies a table column based on a $definition
supportSequences()¶
Check whether the database system requires a sequence to produce auto-numeric values
useExplicitIdValue()¶
Check whether the database system requires an explicit value for identity columns
getDsnDefaults()¶
Returns PDO adapter DSN defaults as a key-value map.
isConnectionError()¶
Recognizes a PostgreSQL connection-loss failure by SQLSTATE (connection exception class 08, or admin/crash shutdown 57P0x) with a message fallback.
Db\Adapter\Pdo\Sqlite¶
Class Source on GitHub
Specific functions for the SQLite database system
Phalcon\Db\Adapter\AbstractAdapterPhalcon\Db\Adapter\Pdo\AbstractPdoPhalcon\Db\Adapter\Pdo\Sqlite
Uses Phalcon\Db\Adapter\Pdo\AbstractPdo · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Enum · Phalcon\Db\Exception · Phalcon\Db\Exceptions\MissingSqliteDatabase · Phalcon\Db\Index · Phalcon\Db\IndexInterface · Phalcon\Db\RawValue · Phalcon\Db\Reference · Phalcon\Db\ReferenceInterface
Method Summary¶
public
__construct( array $descriptor )
Constructor for Phalcon\Db\Adapter\Pdo\Sqlite
public
void
connect( array $descriptor = [] )
This method is automatically called in Phalcon\Db\Adapter\Pdo
public
array
describeColumns(string $tableName,string|null $schemaName = null)
Returns an array of Phalcon\Db\Column objects describing a table
public
array
describeIndexes(string $tableName,string|null $schemaName = null)
Lists table indexes
public
array
describeReferences(string $tableName,string|null $schemaName = null)
Lists table references
public
RawValue
getDefaultValue()
Returns the default value to make the RBDM use the default value declared
public
bool
supportsDefaultValue()
SQLite does not support the DEFAULT keyword
public
bool
useExplicitIdValue()
Check whether the database system requires an explicit value for identity
protected
array
getDsnDefaults()
Returns PDO adapter DSN defaults as a key-value map.
Properties¶
protected
string
$dialectType = "sqlite"
protected
string
$type = "sqlite"
Methods¶
__construct()¶
Constructor for Phalcon\Db\Adapter\Pdo\Sqlite
connect()¶
This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. Call it when you need to restore a database connection.
describeColumns()¶
Returns an array of Phalcon\Db\Column objects describing a table
describeIndexes()¶
Lists table indexes
describeReferences()¶
Lists table references
getDefaultValue()¶
Returns the default value to make the RBDM use the default value declared in the table definition
// Inserting a new invoice with a valid default value for the column 'inv_total'
$success = $connection->insert(
"co_invoices",
[
"Test Invoice",
$connection->getDefaultValue(),
],
[
"inv_title",
"inv_total",
]
);
supportsDefaultValue()¶
SQLite does not support the DEFAULT keyword
useExplicitIdValue()¶
Check whether the database system requires an explicit value for identity columns
getDsnDefaults()¶
Returns PDO adapter DSN defaults as a key-value map.
Db\Check¶
Class Source on GitHub
Allows to define CHECK constraints on tables. CHECK constraints enforce
a boolean SQL predicate on each row of the table; rows that fail the
predicate are rejected at INSERT/UPDATE time.
use Phalcon\Db\Check;
$positivePrice = new Check(
"chk_price_positive",
[
"expression" => "price > 0",
]
);
// Used inside a createTable() definition
$connection->createTable(
"products",
null,
[
"columns" => [ ... ],
"checks" => [$positivePrice],
]
);
Phalcon\Db\Check- implementsPhalcon\Db\CheckInterface
Uses Phalcon\Db\Exceptions\CheckExpressionRequired · Phalcon\Db\Exceptions\InvalidCheckExpression
Method Summary¶
public
__construct(string $name,array $definition)
Phalcon\Db\Check constructor.
public
string
getExpression()
Returns the CHECK expression
public
string
getName()
Returns the constraint name (may be an empty string for unnamed)
Properties¶
protected
string
$expression
The boolean SQL predicate this constraint enforces.
protected
string
$name
The CHECK constraint name. An empty string indicates an unnamed
constraint - the dialect will emit the clause without a CONSTRAINT
prefix in that case.
Methods¶
__construct()¶
Phalcon\Db\Check constructor.
getExpression()¶
Returns the CHECK expression
getName()¶
Returns the constraint name (may be an empty string for unnamed)
Db\CheckInterface¶
Interface Source on GitHub
Phalcon\Db\CheckInterface
Phalcon\Contracts\Db\CheckPhalcon\Db\CheckInterface
Uses Phalcon\Contracts\Db\Check
Db\Column¶
Class Source on GitHub
Allows to define columns to be used on create or alter table operations
use Phalcon\Db\Column as Column;
// Column definition
$column = new Column(
"id",
[
"type" => Column::TYPE_INTEGER,
"size" => 10,
"unsigned" => true,
"notNull" => true,
"autoIncrement" => true,
"first" => true,
"comment" => "",
]
);
// Add column to existing table
$connection->addColumn("co_invoices", null, $column);
Phalcon\Db\Column- implementsPhalcon\Db\ColumnInterface
Uses Phalcon\Db\Exceptions\ColumnTypeRejectsAutoIncrement · Phalcon\Db\Exceptions\ColumnTypeRejectsScale · Phalcon\Db\Exceptions\ColumnTypeRequired · Phalcon\Db\Exceptions\GeneratedAutoIncrementConflict · Phalcon\Db\Exceptions\GeneratedDefaultConflict · Phalcon\Db\Exceptions\InvalidGenerationExpression
Method Summary¶
public
__construct(string $name,array $definition)
Phalcon\Db\Column constructor
public
string|null
getAfterPosition()
Check whether field absolute to position in table
public
int
getBindType()
Returns the type of bind handling
public
string|null
getComment()
Column's comment
public
mixed
getDefault()
Default column value
public
string|null
getGenerationExpression()
Returns the generation expression for a generated/computed column.
public
string
getName()
Column's name
public
int
getScale()
Integer column number scale
public
int|string
getSize()
Integer column size
public
int|string
getType()
Column data type
public
int
getTypeReference()
Column data type reference
public
array|int|string
getTypeValues()
Column data type values
public
bool
hasDefault()
Check whether column has default value
public
bool
isArray()
Whether the column is an array of its base type. Recognized by the
public
bool
isAutoIncrement()
Auto-Increment
public
bool
isFirst()
Check whether column has the first position in the table
public
bool
isGenerated()
Whether the column is a generated/computed column.
public
bool
isGenerationStored()
Whether a generated column is STORED. false means VIRTUAL.
public
bool
isInvisible()
Whether the column is declared INVISIBLE (MySQL 8.0.23+).
public
bool
isNotNull()
Not null
public
bool
isNumeric()
Check whether column have a numeric type
public
bool
isPrimary()
Column is part of the primary key?
public
bool
isUnsigned()
Returns true if number column is unsigned
Constants¶
int
BIND_PARAM_BLOB = 3
Bind Type Blob
int
BIND_PARAM_BOOL = 5
Bind Type Bool
int
BIND_PARAM_DECIMAL = 32
Bind Type Decimal
int
BIND_PARAM_INT = 1
Bind Type Integer
int
BIND_PARAM_NULL = 0
Bind Type Null
int
BIND_PARAM_STR = 2
Bind Type String
int
BIND_SKIP = 1024
Skip binding by type
int
TYPE_BIGINTEGER = 14
Big integer abstract data type
int
TYPE_BINARY = 27
Binary abstract data type
int
TYPE_BIT = 19
Bit abstract data type
int
TYPE_BLOB = 11
Blob abstract data type
int
TYPE_BOOLEAN = 8
Bool abstract data type
int
TYPE_BYTEA = 30
PostgreSQL BYTEA binary type
int
TYPE_CHAR = 5
Char abstract data type
int
TYPE_CIDR = 32
PostgreSQL CIDR network-address type
int
TYPE_DATE = 1
Date abstract data type
int
TYPE_DATERANGE = 39
PostgreSQL DATERANGE range-of-date type
int
TYPE_DATETIME = 4
Datetime abstract data type
int
TYPE_DECIMAL = 3
Decimal abstract data type
int
TYPE_DOUBLE = 9
Double abstract data type
int
TYPE_ENUM = 18
Enum abstract data type
int
TYPE_FLOAT = 7
Float abstract data type
int
TYPE_GEOMETRY = 40
Spatial GEOMETRY base type (MySQL 5.7+; PostgreSQL + PostGIS)
int
TYPE_GEOMETRYCOLLECTION = 47
Spatial GEOMETRYCOLLECTION type
int
TYPE_INET = 31
PostgreSQL INET IPv4/IPv6 address type
int
TYPE_INT4RANGE = 34
PostgreSQL INT4RANGE range-of-integer type
int
TYPE_INT8RANGE = 35
PostgreSQL INT8RANGE range-of-bigint type
int
TYPE_INTEGER = 0
Int abstract data type
int
TYPE_JSON = 15
Json abstract data type
int
TYPE_JSONB = 16
Jsonb abstract data type
int
TYPE_LINESTRING = 42
Spatial LINESTRING type
int
TYPE_LONGBLOB = 13
Longblob abstract data type
int
TYPE_LONGTEXT = 24
Longtext abstract data type
int
TYPE_MACADDR = 33
PostgreSQL MACADDR MAC-address type
int
TYPE_MEDIUMBLOB = 12
Mediumblob abstract data type
int
TYPE_MEDIUMINTEGER = 21
Mediumintegerr abstract data type
int
TYPE_MEDIUMTEXT = 23
Mediumtext abstract data type
int
TYPE_MULTILINESTRING = 45
Spatial MULTILINESTRING type
int
TYPE_MULTIPOINT = 44
Spatial MULTIPOINT type
int
TYPE_MULTIPOLYGON = 46
Spatial MULTIPOLYGON type
int
TYPE_NUMRANGE = 36
PostgreSQL NUMRANGE range-of-numeric type
int
TYPE_POINT = 41
Spatial POINT type
int
TYPE_POLYGON = 43
Spatial POLYGON type
int
TYPE_SMALLINTEGER = 22
Smallint abstract data type
int
TYPE_TEXT = 6
Text abstract data type
int
TYPE_TIME = 20
Time abstract data type
int
TYPE_TIMESTAMP = 17
Timestamp abstract data type
int
TYPE_TINYBLOB = 10
Tinyblob abstract data type
int
TYPE_TINYINTEGER = 26
Tinyint abstract data type
int
TYPE_TINYTEXT = 25
Tinytext abstract data type
int
TYPE_TSRANGE = 37
PostgreSQL TSRANGE range-of-timestamp (without time zone) type
int
TYPE_TSTZRANGE = 38
PostgreSQL TSTZRANGE range-of-timestamp (with time zone) type
int
TYPE_UUID = 29
UUID abstract data type
int
TYPE_VARBINARY = 28
Varbinary abstract data type
int
TYPE_VARCHAR = 2
Varchar abstract data type
Properties¶
protected
string|null
$after = null
Column Position
protected
int
$bindType = 2
Bind Type
protected
string|null
$comment = null
Column's comment
protected
mixed|null
$defaultValue = null
Default column value
protected
string|null
$generated = null
Generation expression for GENERATED ALWAYS AS (...). Null when the
column is not generated.
protected
bool
$generationStored = false
Whether a generated column is STORED (true) or VIRTUAL (false).
PostgreSQL only supports STORED and emits it regardless of this
flag.
protected
bool
$isArray = false
Whether the column is an array of its base type (PostgreSQL).
protected
bool
$isAutoIncrement = false
Column is autoIncrement?
protected
bool
$isFirst = false
Position is first
protected
bool
$isInvisible = false
Whether the column is declared INVISIBLE (MySQL 8.0.23+).
protected
bool
$isNotNull = true
Column not nullable?
Default SQL definition is NOT NULL.
protected
bool
$isNumeric = false
The column have some numeric type?
protected
bool
$isPrimary = false
Column is part of the primary key?
protected
bool
$isUnsigned = false
Integer column unsigned?
protected
string
$name
protected
int
$scale = 0
Integer column number scale
protected
int|string
$size = 0
Integer column size
protected
int|string
$type
Column data type
protected
int
$typeReference = -1
Column data type reference
protected
array|int|string
$typeValues = []
Column data type values
Methods¶
__construct()¶
Phalcon\Db\Column constructor
getAfterPosition()¶
Check whether field absolute to position in table
getBindType()¶
Returns the type of bind handling
getComment()¶
Column's comment
getDefault()¶
Default column value
getGenerationExpression()¶
Returns the generation expression for a generated/computed column. Returns null when the column is not generated.
getName()¶
Column's name
getScale()¶
Integer column number scale
getSize()¶
Integer column size
getType()¶
Column data type
getTypeReference()¶
Column data type reference
getTypeValues()¶
Column data type values
hasDefault()¶
Check whether column has default value
isArray()¶
Whether the column is an array of its base type. Recognized by the
PostgreSQL dialect (e.g. INTEGER[], TEXT[]); MySQL and SQLite
ignore the flag.
isAutoIncrement()¶
Auto-Increment
isFirst()¶
Check whether column has the first position in the table
isGenerated()¶
Whether the column is a generated/computed column.
isGenerationStored()¶
Whether a generated column is STORED. false means VIRTUAL.
isInvisible()¶
Whether the column is declared INVISIBLE (MySQL 8.0.23+).
isNotNull()¶
Not null
isNumeric()¶
Check whether column have a numeric type
isPrimary()¶
Column is part of the primary key?
isUnsigned()¶
Returns true if number column is unsigned
Db\ColumnInterface¶
Interface Source on GitHub
Phalcon\Db\ColumnInterface
Phalcon\Contracts\Db\ColumnPhalcon\Db\ColumnInterface
Uses Phalcon\Contracts\Db\Column
Db\Dialect¶
Abstract Source on GitHub
This is the base class to each database dialect. This implements common methods to transform intermediate code into its RDBMS related syntax
Phalcon\Db\Dialect- implementsPhalcon\Db\DialectInterface
Uses Phalcon\Db\Exceptions\ConflictTargetColumnRequired · Phalcon\Db\Exceptions\ConflictUpdateColumnRequired · Phalcon\Db\Exceptions\InvalidGroupByExpression · Phalcon\Db\Exceptions\InvalidListExpression · Phalcon\Db\Exceptions\InvalidOrderByExpression · Phalcon\Db\Exceptions\InvalidSqlExpression · Phalcon\Db\Exceptions\InvalidSqlExpressionType · Phalcon\Db\Exceptions\InvalidUnaryExpression · Phalcon\Db\Exceptions\MaterializedViewsNotSupported · Phalcon\Db\Exceptions\MissingDefinitionKey · Phalcon\Db\Exceptions\ReturningNotSupported · Phalcon\Db\Exceptions\UnsupportedOperator · Phalcon\Support\Settings
Method Summary¶
public
string
createMaterializedView(string $viewName,array $definition,string|null $schemaName = null)
Generates SQL to create a materialized view. Supported by PostgreSQL;
public
string
createSavepoint( string $name )
Generate SQL to create a new savepoint
public
string
dropMaterializedView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a materialized view (PostgreSQL only).
public
string
escape(string $input,string $escapeChar = "")
Escape identifiers
public
string
escapeSchema(string $input,string $escapeChar = "")
Escape Schema
public
string
forUpdate(string $sqlQuery,string $modifier = "")
Returns a SQL modified with a FOR UPDATE clause. The optional
public
string
getColumnList(array $columnList,string $escapeChar = "",array $bindCounts = [])
Gets a list of columns with escaped identifiers
public
array
getCustomFunctions()
Returns registered functions
public
string
getSqlColumn(array|string $column,string $escapeChar = "",array $bindCounts = [])
Resolve Column expressions
public
string
getSqlExpression(array $expression,string $escapeChar = "",array $bindCounts = [])
Transforms an intermediate representation for an expression into a
public
string
getSqlTable(array|string $tableName,string $escapeChar = "")
Transform an intermediate representation of a schema/table into a
public
string
limit(string $sqlQuery,array|int $number)
Generates the SQL for LIMIT clause
public
string
onConflictUpdate(string $sqlQuery,array $conflictColumns,array $updateColumns)
Appends an ON CONFLICT (col, ...) DO UPDATE SET col = excluded.col
public
string
refreshMaterializedView(string $viewName,string|null $schemaName = null,bool $concurrent = false)
Generates SQL to refresh a materialized view (PostgreSQL only).
public
static
registerCustomFunction(string $name,callable $customFunction)
Registers custom SQL functions
public
string
releaseSavepoint( string $name )
Generate SQL to release a savepoint
public
string
returning(string $sqlQuery,array $columns)
Returns a SQL statement extended with a RETURNING clause.
public
string
rollbackSavepoint( string $name )
Generate SQL to rollback a savepoint
public
string
select( array $definition )
Builds a SELECT statement
public
bool
supportsAlterTable()
Checks whether the platform supports the full ALTER TABLE matrix:
public
bool
supportsMaterializedViews()
Checks whether the platform supports materialized views. Only PostgreSQL
public
bool
supportsOnConflictUpdate()
Checks whether the platform supports the ON CONFLICT (...) DO UPDATE
public
bool
supportsReleaseSavepoints()
Checks whether the platform supports releasing savepoints.
public
bool
supportsReturning()
Checks whether the platform supports the RETURNING clause. MySQL
public
bool
supportsSavepoints()
Checks whether the platform supports savepoints
protected
int
checkColumnType( ColumnInterface $column )
Checks the column type and if not string it returns the type reference
protected
string
checkColumnTypeSql( ColumnInterface $column )
Checks the column type and returns the updated SQL statement
protected
string
getCheckClause(CheckInterface $check,string $escapeChar = "`")
Builds a CHECK constraint clause from a CheckInterface, using the
protected
string
getColumnSize( ColumnInterface $column )
Returns the size of the column enclosed in parentheses
protected
string
getColumnSizeAndScale( ColumnInterface $column )
Returns the column size and scale enclosed in parentheses
protected
string
getGeneratedClause(ColumnInterface $column,bool $forceStored = false)
Builds the GENERATED ALWAYS AS (<expr>) VIRTUAL|STORED clause for a
protected
string
getIndexColumnList(IndexInterface $index,bool $wrapExpressions = true)
Builds the per-index parenthesized column list, honoring per-column
protected
string
getSqlExpressionAll(array $expression,string $escapeChar = "")
Resolve *
protected
string
getSqlExpressionBinaryOperations(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve binary operations expressions
protected
string
getSqlExpressionCase(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve CASE expressions
protected
string
getSqlExpressionCastValue(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve CAST of values
protected
string
getSqlExpressionConvertValue(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve CONVERT of values encodings
protected
string
getSqlExpressionFrom(array|string $expression,string $escapeChar = "")
Resolve a FROM clause
protected
string
getSqlExpressionFunctionCall(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve function calls
protected
string
getSqlExpressionGroupBy(array|string $expression,string $escapeChar = "",array $bindCounts = [])
Resolve a GROUP BY clause
protected
string
getSqlExpressionHaving(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve a HAVING clause
protected
string
getSqlExpressionJoins(array|string $expression,string $escapeChar = "",array $bindCounts = [])
Resolve a JOINs clause
protected
string
getSqlExpressionLimit(array|string $expression,string $escapeChar = "",array $bindCounts = [])
Resolve a LIMIT clause
protected
string
getSqlExpressionList(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve Lists
protected
string
getSqlExpressionObject(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve object expressions
protected
string
getSqlExpressionOrderBy(array|string $expression,string $escapeChar = "",array $bindCounts = [])
Resolve an ORDER BY clause
protected
string
getSqlExpressionQualified(array $expression,string $escapeChar = "")
Resolve qualified expressions
protected
string
getSqlExpressionScalar(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve Column expressions
protected
string
getSqlExpressionUnaryOperations(array $expression,string $escapeChar = "",array $bindCounts = [])
Resolve unary operations expressions
protected
string
getSqlExpressionWhere(array|string $expression,string $escapeChar = "",array $bindCounts = [])
Resolve a WHERE clause
protected
string
prepareColumnAlias(string $qualified,string $alias = "",string $escapeChar = "")
Prepares column for this RDBMS
protected
string
prepareQualified(string $column,string $domain = "",string $escapeChar = "")
Prepares qualified for this RDBMS
protected
string
prepareTable(string $tableName,string|null $schemaName = null,string $alias = "",string $escapeChar = "")
Prepares table for this RDBMS
Properties¶
protected
array
$customFunctions = []
protected
string
$escapeChar
protected
array
$guardedOperators = [...]
Dialect-specific operators that a concrete dialect must opt into via
$supportedOperators; using one elsewhere throws.
protected
array
$supportedOperators = []
Subset of $guardedOperators that this dialect emits. Overridden per
dialect.
Methods¶
createMaterializedView()¶
public function createMaterializedView(
string $viewName,
array $definition,
string|null $schemaName = null
): string;
Generates SQL to create a materialized view. Supported by PostgreSQL; MySQL and SQLite inherit this throw.
createSavepoint()¶
Generate SQL to create a new savepoint
dropMaterializedView()¶
public function dropMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a materialized view (PostgreSQL only).
escape()¶
Escape identifiers
escapeSchema()¶
Escape Schema
forUpdate()¶
Returns a SQL modified with a FOR UPDATE clause. The optional
modifier appends a row-lock disposition keyword.
$sql = $dialect->forUpdate("SELECT * FROM co_invoices");
echo $sql; // SELECT * FROM co_invoices FOR UPDATE
$sql = $dialect->forUpdate(
"SELECT * FROM co_invoices",
Dialect::LOCK_NOWAIT
);
echo $sql; // SELECT * FROM co_invoices FOR UPDATE NOWAIT
getColumnList()¶
final public function getColumnList(
array $columnList,
string $escapeChar = "",
array $bindCounts = []
): string;
Gets a list of columns with escaped identifiers
getCustomFunctions()¶
Returns registered functions
getSqlColumn()¶
final public function getSqlColumn(
array|string $column,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve Column expressions
getSqlExpression()¶
public function getSqlExpression(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Transforms an intermediate representation for an expression into a database system valid expression
getSqlTable()¶
Transform an intermediate representation of a schema/table into a database system valid expression
limit()¶
Generates the SQL for LIMIT clause
// SELECT * FROM co_invoices LIMIT 10
echo $dialect->limit(
"SELECT * FROM co_invoices",
10
);
// SELECT * FROM co_invoices LIMIT 10 OFFSET 50
echo $dialect->limit(
"SELECT * FROM co_invoices",
[10, 50]
);
onConflictUpdate()¶
public function onConflictUpdate(
string $sqlQuery,
array $conflictColumns,
array $updateColumns
): string;
Appends an ON CONFLICT (col, ...) DO UPDATE SET col = excluded.col
upsert clause to the supplied INSERT statement. Supported by
PostgreSQL 9.5+ and SQLite 3.24+. MySQL overrides this method to
throw.
refreshMaterializedView()¶
public function refreshMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $concurrent = false
): string;
Generates SQL to refresh a materialized view (PostgreSQL only).
registerCustomFunction()¶
Registers custom SQL functions
releaseSavepoint()¶
Generate SQL to release a savepoint
returning()¶
Returns a SQL statement extended with a RETURNING clause.
Supported by PostgreSQL and SQLite 3.35+; MySQL inherits the throw.
rollbackSavepoint()¶
Generate SQL to rollback a savepoint
select()¶
Builds a SELECT statement
supportsAlterTable()¶
Checks whether the platform supports the full ALTER TABLE matrix:
modifying existing columns and adding or dropping foreign keys, primary
keys, and check constraints. SQLite returns false - those operations
throw a dedicated Sqlite*NotSupported exception there (basic
ADD COLUMN remains available).
supportsMaterializedViews()¶
Checks whether the platform supports materialized views. Only PostgreSQL
returns true; createMaterializedView() throws on the other dialects.
supportsOnConflictUpdate()¶
Checks whether the platform supports the ON CONFLICT (...) DO UPDATE
upsert clause. MySQL returns false; onConflictUpdate() throws there.
supportsReleaseSavepoints()¶
Checks whether the platform supports releasing savepoints.
supportsReturning()¶
Checks whether the platform supports the RETURNING clause. MySQL
returns false; returning() throws there.
supportsSavepoints()¶
Checks whether the platform supports savepoints
checkColumnType()¶
Checks the column type and if not string it returns the type reference
checkColumnTypeSql()¶
Checks the column type and returns the updated SQL statement
getCheckClause()¶
Builds a CHECK constraint clause from a CheckInterface, using the
provided escape character for the constraint name.
getColumnSize()¶
Returns the size of the column enclosed in parentheses
getColumnSizeAndScale()¶
Returns the column size and scale enclosed in parentheses
getGeneratedClause()¶
protected function getGeneratedClause(
ColumnInterface $column,
bool $forceStored = false
): string;
Builds the GENERATED ALWAYS AS (<expr>) VIRTUAL|STORED clause for a
generated/computed column. Returns an empty string when the column is
not generated. When forceStored is true the clause is always
emitted as STORED (PostgreSQL uses this).
getIndexColumnList()¶
protected function getIndexColumnList(
IndexInterface $index,
bool $wrapExpressions = true
): string;
Builds the per-index parenthesized column list, honoring per-column
sort directions and RawValue expression entries.
getSqlExpressionAll()¶
Resolve *
getSqlExpressionBinaryOperations()¶
final protected function getSqlExpressionBinaryOperations(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve binary operations expressions
getSqlExpressionCase()¶
final protected function getSqlExpressionCase(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve CASE expressions
getSqlExpressionCastValue()¶
final protected function getSqlExpressionCastValue(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve CAST of values
getSqlExpressionConvertValue()¶
final protected function getSqlExpressionConvertValue(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve CONVERT of values encodings
getSqlExpressionFrom()¶
final protected function getSqlExpressionFrom(
array|string $expression,
string $escapeChar = ""
): string;
Resolve a FROM clause
getSqlExpressionFunctionCall()¶
final protected function getSqlExpressionFunctionCall(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve function calls
getSqlExpressionGroupBy()¶
final protected function getSqlExpressionGroupBy(
array|string $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve a GROUP BY clause
getSqlExpressionHaving()¶
final protected function getSqlExpressionHaving(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve a HAVING clause
getSqlExpressionJoins()¶
final protected function getSqlExpressionJoins(
array|string $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve a JOINs clause
@todo Isn't expression just an array?
getSqlExpressionLimit()¶
final protected function getSqlExpressionLimit(
array|string $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve a LIMIT clause
getSqlExpressionList()¶
final protected function getSqlExpressionList(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve Lists
getSqlExpressionObject()¶
final protected function getSqlExpressionObject(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve object expressions
getSqlExpressionOrderBy()¶
final protected function getSqlExpressionOrderBy(
array|string $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve an ORDER BY clause
getSqlExpressionQualified()¶
final protected function getSqlExpressionQualified(
array $expression,
string $escapeChar = ""
): string;
Resolve qualified expressions
getSqlExpressionScalar()¶
final protected function getSqlExpressionScalar(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve Column expressions
getSqlExpressionUnaryOperations()¶
final protected function getSqlExpressionUnaryOperations(
array $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve unary operations expressions
getSqlExpressionWhere()¶
final protected function getSqlExpressionWhere(
array|string $expression,
string $escapeChar = "",
array $bindCounts = []
): string;
Resolve a WHERE clause
prepareColumnAlias()¶
protected function prepareColumnAlias(
string $qualified,
string $alias = "",
string $escapeChar = ""
): string;
Prepares column for this RDBMS
prepareQualified()¶
protected function prepareQualified(
string $column,
string $domain = "",
string $escapeChar = ""
): string;
Prepares qualified for this RDBMS
prepareTable()¶
protected function prepareTable(
string $tableName,
string|null $schemaName = null,
string $alias = "",
string $escapeChar = ""
): string;
Prepares table for this RDBMS
Db\DialectInterface¶
Interface Source on GitHub
Phalcon\Db\DialectInterface
Phalcon\Contracts\Db\DialectPhalcon\Db\DialectInterface
Uses Phalcon\Contracts\Db\Dialect
Db\Dialect\Mysql¶
Class Source on GitHub
Generates database specific SQL for the MySQL RDBMS
Phalcon\Db\DialectPhalcon\Db\Dialect\Mysql
Uses Phalcon\Db\CheckInterface · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Dialect · Phalcon\Db\Dialect\Traits\TextTrait · Phalcon\Db\Exception · Phalcon\Db\Exceptions\MissingDefinitionKey · Phalcon\Db\Exceptions\MysqlOnConflictNotSupported · Phalcon\Db\IndexInterface · Phalcon\Db\ReferenceInterface
Method Summary¶
public
string
addCheck(string $tableName,string $schemaName,CheckInterface $check)
Generates SQL to add a CHECK constraint to an existing table.
public
string
addColumn(string $tableName,string $schemaName,ColumnInterface $column)
Generates SQL to add a column to a table
public
string
addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference)
Generates SQL to add an index to a table
public
string
addIndex(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add an index to a table
public
string
addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add the primary key to a table
public
string
createTable(string $tableName,string $schemaName,array $definition)
Generates SQL to create a table
public
string
createView(string $viewName,array $definition,string|null $schemaName = null)
Generates SQL to create a view
public
string
describeColumns(string $tableName,string|null $schemaName = null)
Generates SQL describing a table
public
string
describeIndexes(string $tableName,string|null $schemaName = null)
Generates SQL to query indexes on a table
public
string
describeReferences(string $tableName,string|null $schemaName = null)
Generates SQL to query foreign keys on a table
public
string
dropCheck(string $tableName,string $schemaName,string $checkName)
Generates SQL to delete a CHECK constraint from a table.
public
string
dropColumn(string $tableName,string $schemaName,string $columnName)
Generates SQL to delete a column from a table
public
string
dropForeignKey(string $tableName,string $schemaName,string $referenceName)
Generates SQL to delete a foreign key from a table
public
string
dropIndex(string $tableName,string $schemaName,string $indexName)
Generates SQL to delete an index from a table
public
string
dropPrimaryKey(string $tableName,string $schemaName)
Generates SQL to delete primary key from a table
public
string
dropTable(string $tableName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a table
public
string
dropView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a view
public
string
getColumnDefinition( ColumnInterface $column )
Gets the column name in MySQL
public
string
getForeignKeyChecks()
Generates SQL to check DB parameter FOREIGN_KEY_CHECKS.
public
string
listTables( string|null $schemaName = null )
List all tables in database
public
string
listViews( string|null $schemaName = null )
Generates the SQL to list all views of a schema or user
public
string
modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface|null $currentColumn = null)
Generates SQL to modify a column in a table
public
string
onConflictUpdate(string $sqlQuery,array $conflictColumns,array $updateColumns)
MySQL does not support the SQL-standard ON CONFLICT DO UPDATE
public
string
sharedLock(string $sqlQuery,string $modifier = "")
Returns a SQL modified with a LOCK IN SHARE MODE clause
public
bool
supportsOnConflictUpdate()
MySQL does not support the SQL-standard ON CONFLICT (...) DO UPDATE
public
string
tableExists(string $tableName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.table
public
string
tableOptions(string $tableName,string|null $schemaName = null)
Generates the SQL to describe the table creation options
public
string
truncateTable(string $tableName,string $schemaName = "")
Generates SQL to truncate a table
public
string
viewExists(string $viewName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.view
Properties¶
protected
string
$escapeChar = "`"
protected
array
$supportedOperators = [...]
Methods¶
addCheck()¶
Generates SQL to add a CHECK constraint to an existing table. Enforced by MySQL 8.0.16+.
addColumn()¶
public function addColumn(
string $tableName,
string $schemaName,
ColumnInterface $column
): string;
Generates SQL to add a column to a table
addForeignKey()¶
public function addForeignKey(
string $tableName,
string $schemaName,
ReferenceInterface $reference
): string;
Generates SQL to add an index to a table
addIndex()¶
Generates SQL to add an index to a table
addPrimaryKey()¶
public function addPrimaryKey(
string $tableName,
string $schemaName,
IndexInterface $index
): string;
Generates SQL to add the primary key to a table
createTable()¶
Generates SQL to create a table
createView()¶
public function createView(
string $viewName,
array $definition,
string|null $schemaName = null
): string;
Generates SQL to create a view
describeColumns()¶
Generates SQL describing a table
describeIndexes()¶
Generates SQL to query indexes on a table
describeReferences()¶
Generates SQL to query foreign keys on a table
dropCheck()¶
Generates SQL to delete a CHECK constraint from a table.
dropColumn()¶
Generates SQL to delete a column from a table
dropForeignKey()¶
public function dropForeignKey(
string $tableName,
string $schemaName,
string $referenceName
): string;
Generates SQL to delete a foreign key from a table
dropIndex()¶
Generates SQL to delete an index from a table
dropPrimaryKey()¶
Generates SQL to delete primary key from a table
dropTable()¶
public function dropTable(
string $tableName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a table
dropView()¶
public function dropView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a view
getColumnDefinition()¶
Gets the column name in MySQL
getForeignKeyChecks()¶
Generates SQL to check DB parameter FOREIGN_KEY_CHECKS.
listTables()¶
List all tables in database
listViews()¶
Generates the SQL to list all views of a schema or user
modifyColumn()¶
public function modifyColumn(
string $tableName,
string $schemaName,
ColumnInterface $column,
ColumnInterface|null $currentColumn = null
): string;
Generates SQL to modify a column in a table
onConflictUpdate()¶
public function onConflictUpdate(
string $sqlQuery,
array $conflictColumns,
array $updateColumns
): string;
MySQL does not support the SQL-standard ON CONFLICT DO UPDATE
upsert syntax - it has its own INSERT ... ON DUPLICATE KEY UPDATE.
sharedLock()¶
Returns a SQL modified with a LOCK IN SHARE MODE clause
$sql = $dialect->sharedLock("SELECT * FROM co_invoices");
echo $sql; // SELECT * FROM co_invoices LOCK IN SHARE MODE
supportsOnConflictUpdate()¶
MySQL does not support the SQL-standard ON CONFLICT (...) DO UPDATE
upsert clause; onConflictUpdate() throws.
tableExists()¶
Generates SQL checking for the existence of a schema.table
tableOptions()¶
Generates the SQL to describe the table creation options
truncateTable()¶
Generates SQL to truncate a table
viewExists()¶
Generates SQL checking for the existence of a schema.view
Db\Dialect\Postgresql¶
Class Source on GitHub
Generates database specific SQL for the PostgreSQL RDBMS
Phalcon\Db\DialectPhalcon\Db\Dialect\Postgresql
Uses Phalcon\Db\CheckInterface · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Dialect · Phalcon\Db\Exception · Phalcon\Db\Exceptions\MissingDefinitionKey · Phalcon\Db\Exceptions\ReturningRequiresColumn · Phalcon\Db\Exceptions\UnrecognizedDataType · Phalcon\Db\IndexInterface · Phalcon\Db\RawValue · Phalcon\Db\ReferenceInterface
Method Summary¶
public
string
addCheck(string $tableName,string $schemaName,CheckInterface $check)
Generates SQL to add a CHECK constraint to an existing table.
public
string
addColumn(string $tableName,string $schemaName,ColumnInterface $column)
Generates SQL to add a column to a table
public
string
addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference)
Generates SQL to add an index to a table
public
string
addIndex(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add an index to a table
public
string
addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add the primary key to a table
public
string
createMaterializedView(string $viewName,array $definition,string|null $schemaName = null)
Generates SQL to create a materialized view.
public
string
createTable(string $tableName,string $schemaName,array $definition)
Generates SQL to create a table
public
string
createView(string $viewName,array $definition,string|null $schemaName = null)
Generates SQL to create a view
public
string
describeColumns(string $tableName,string|null $schemaName = null)
Generates SQL describing a table
public
string
describeIndexes(string $tableName,string|null $schemaName = null)
Generates SQL to query indexes on a table
public
string
describeReferences(string $tableName,string|null $schemaName = null)
Generates SQL to query foreign keys on a table
public
string
dropCheck(string $tableName,string $schemaName,string $checkName)
Generates SQL to delete a CHECK constraint from a table.
public
string
dropColumn(string $tableName,string $schemaName,string $columnName)
Generates SQL to delete a column from a table
public
string
dropForeignKey(string $tableName,string $schemaName,string $referenceName)
Generates SQL to delete a foreign key from a table
public
string
dropIndex(string $tableName,string $schemaName,string $indexName)
Generates SQL to delete an index from a table
public
string
dropMaterializedView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a materialized view.
public
string
dropPrimaryKey(string $tableName,string $schemaName)
Generates SQL to delete primary key from a table
public
string
dropTable(string $tableName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a table
public
string
dropView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a view
public
string
getColumnDefinition( ColumnInterface $column )
Gets the column name in PostgreSQL
public
string
listTables( string|null $schemaName = null )
List all tables in database
public
string
listViews( string|null $schemaName = null )
Generates the SQL to list all views of a schema or user
public
string
modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface|null $currentColumn = null)
Generates SQL to modify a column in a table
public
string
refreshMaterializedView(string $viewName,string|null $schemaName = null,bool $concurrent = false)
Generates SQL to refresh a materialized view.
public
string
returning(string $sqlQuery,array $columns)
Appends a RETURNING clause to the supplied INSERT/UPDATE/DELETE
public
string
sharedLock(string $sqlQuery,string $modifier = "")
Returns a SQL modified a shared lock statement. For now this method
public
bool
supportsMaterializedViews()
PostgreSQL supports materialized views (CREATE MATERIALIZED VIEW).
public
bool
supportsReturning()
PostgreSQL supports the RETURNING clause.
public
string
tableExists(string $tableName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.table
public
string
tableOptions(string $tableName,string|null $schemaName = null)
Generates the SQL to describe the table creation options
public
string
truncateTable(string $tableName,string|null $schemaName = "")
Generates SQL to truncate a table
public
string
viewExists(string $viewName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.view
protected
string
castDefault( ColumnInterface $column )
protected
string
getTableOptions( array $definition )
Properties¶
protected
string
$escapeChar = "\""
protected
array
$supportedOperators = [...]
Methods¶
addCheck()¶
Generates SQL to add a CHECK constraint to an existing table.
addColumn()¶
public function addColumn(
string $tableName,
string $schemaName,
ColumnInterface $column
): string;
Generates SQL to add a column to a table
addForeignKey()¶
public function addForeignKey(
string $tableName,
string $schemaName,
ReferenceInterface $reference
): string;
Generates SQL to add an index to a table
addIndex()¶
Generates SQL to add an index to a table
addPrimaryKey()¶
public function addPrimaryKey(
string $tableName,
string $schemaName,
IndexInterface $index
): string;
Generates SQL to add the primary key to a table
createMaterializedView()¶
public function createMaterializedView(
string $viewName,
array $definition,
string|null $schemaName = null
): string;
Generates SQL to create a materialized view.
createTable()¶
Generates SQL to create a table
createView()¶
public function createView(
string $viewName,
array $definition,
string|null $schemaName = null
): string;
Generates SQL to create a view
describeColumns()¶
Generates SQL describing a table
describeIndexes()¶
Generates SQL to query indexes on a table
describeReferences()¶
Generates SQL to query foreign keys on a table
dropCheck()¶
Generates SQL to delete a CHECK constraint from a table.
dropColumn()¶
Generates SQL to delete a column from a table
dropForeignKey()¶
public function dropForeignKey(
string $tableName,
string $schemaName,
string $referenceName
): string;
Generates SQL to delete a foreign key from a table
dropIndex()¶
Generates SQL to delete an index from a table
dropMaterializedView()¶
public function dropMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a materialized view.
dropPrimaryKey()¶
Generates SQL to delete primary key from a table
dropTable()¶
public function dropTable(
string $tableName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a table
dropView()¶
public function dropView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a view
getColumnDefinition()¶
Gets the column name in PostgreSQL
listTables()¶
List all tables in database
listViews()¶
Generates the SQL to list all views of a schema or user
modifyColumn()¶
public function modifyColumn(
string $tableName,
string $schemaName,
ColumnInterface $column,
ColumnInterface|null $currentColumn = null
): string;
Generates SQL to modify a column in a table
refreshMaterializedView()¶
public function refreshMaterializedView(
string $viewName,
string|null $schemaName = null,
bool $concurrent = false
): string;
Generates SQL to refresh a materialized view.
returning()¶
Appends a RETURNING clause to the supplied INSERT/UPDATE/DELETE
statement.
sharedLock()¶
Returns a SQL modified a shared lock statement. For now this method returns the original query
supportsMaterializedViews()¶
PostgreSQL supports materialized views (CREATE MATERIALIZED VIEW).
supportsReturning()¶
PostgreSQL supports the RETURNING clause.
tableExists()¶
Generates SQL checking for the existence of a schema.table
tableOptions()¶
Generates the SQL to describe the table creation options
truncateTable()¶
Generates SQL to truncate a table
viewExists()¶
Generates SQL checking for the existence of a schema.view
castDefault()¶
getTableOptions()¶
Db\Dialect\Sqlite¶
Class Source on GitHub
Generates database specific SQL for the SQLite RDBMS
Phalcon\Db\DialectPhalcon\Db\Dialect\Sqlite
Uses Phalcon\Db\CheckInterface · Phalcon\Db\Column · Phalcon\Db\ColumnInterface · Phalcon\Db\Dialect · Phalcon\Db\Dialect\Traits\TextTrait · Phalcon\Db\Exception · Phalcon\Db\Exceptions\MissingDefinitionKey · Phalcon\Db\Exceptions\ReturningRequiresColumn · Phalcon\Db\Exceptions\SqliteAlterCheckNotSupported · Phalcon\Db\Exceptions\SqliteAlterColumnNotSupported · Phalcon\Db\Exceptions\SqliteAlterForeignKeyNotSupported · Phalcon\Db\Exceptions\SqliteAlterPrimaryKeyNotSupported · Phalcon\Db\Exceptions\SqliteDropCheckNotSupported · Phalcon\Db\Exceptions\SqliteDropForeignKeyNotSupported · Phalcon\Db\Exceptions\SqliteDropPrimaryKeyNotSupported · Phalcon\Db\Exceptions\UnrecognizedDataType · Phalcon\Db\IndexInterface · Phalcon\Db\ReferenceInterface
Method Summary¶
public
string
addCheck(string $tableName,string $schemaName,CheckInterface $check)
SQLite cannot ALTER an existing table to add a CHECK constraint.
public
string
addColumn(string $tableName,string $schemaName,ColumnInterface $column)
Generates SQL to add a column to a table
public
string
addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference)
Generates SQL to add an index to a table
public
string
addIndex(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add an index to a table
public
string
addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index)
Generates SQL to add the primary key to a table
public
string
createTable(string $tableName,string $schemaName,array $definition)
Generates SQL to create a table
public
string
createView(string $viewName,array $definition,string|null $schemaName = null)
Generates SQL to create a view
public
string
describeColumns(string $tableName,string|null $schemaName = null)
Generates SQL describing a table
public
string
describeIndex( string $index )
Generates SQL to query indexes detail on a table
public
string
describeIndexes(string $tableName,string|null $schemaName = null)
Generates SQL to query indexes on a table
public
string
describeReferences(string $tableName,string|null $schemaName = null)
Generates SQL to query foreign keys on a table
public
string
dropCheck(string $tableName,string $schemaName,string $checkName)
SQLite cannot DROP a CHECK constraint from an existing table.
public
string
dropColumn(string $tableName,string $schemaName,string $columnName)
Generates SQL to delete a column from a table
public
string
dropForeignKey(string $tableName,string $schemaName,string $referenceName)
Generates SQL to delete a foreign key from a table
public
string
dropIndex(string $tableName,string $schemaName,string $indexName)
Generates SQL to delete an index from a table
public
string
dropPrimaryKey(string $tableName,string $schemaName)
Generates SQL to delete primary key from a table
public
string
dropTable(string $tableName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a table
public
string
dropView(string $viewName,string|null $schemaName = null,bool $ifExists = true)
Generates SQL to drop a view
public
string
forUpdate(string $sqlQuery,string $modifier = "")
Returns a SQL modified with a FOR UPDATE clause. For SQLite, it returns
public
string
getColumnDefinition( ColumnInterface $column )
Gets the column name in SQLite
public
string
listIndexesSql(string $tableName,string|null $schemaName = null,string|null $keyName = null)
Generates the SQL to get query list of indexes
public
string
listTables( string|null $schemaName = null )
List all tables in database
public
string
listViews( string|null $schemaName = null )
Generates the SQL to list all views of a schema or user
public
string
modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface|null $currentColumn = null)
Generates SQL to modify a column in a table
public
string
returning(string $sqlQuery,array $columns)
Appends a RETURNING clause to the supplied INSERT/UPDATE/DELETE
public
string
sharedLock(string $sqlQuery,string $modifier = "")
Returns a SQL modified a shared lock statement. For now this method
public
bool
supportsAlterTable()
SQLite cannot modify existing columns or add/drop foreign keys, primary
public
bool
supportsReturning()
SQLite (3.35+) supports the RETURNING clause.
public
string
tableExists(string $tableName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.table
public
string
tableOptions(string $tableName,string|null $schemaName = null)
Generates the SQL to describe the table creation options
public
string
truncateTable(string $tableName,string|null $schemaName = "")
Generates SQL to truncate a table
public
string
viewExists(string $viewName,string|null $schemaName = null)
Generates SQL checking for the existence of a schema.view
Properties¶
protected
string
$escapeChar = "\""
protected
array
$supportedOperators = [...]
Methods¶
addCheck()¶
SQLite cannot ALTER an existing table to add a CHECK constraint.
addColumn()¶
public function addColumn(
string $tableName,
string $schemaName,
ColumnInterface $column
): string;
Generates SQL to add a column to a table
addForeignKey()¶
public function addForeignKey(
string $tableName,
string $schemaName,
ReferenceInterface $reference
): string;
Generates SQL to add an index to a table
addIndex()¶
Generates SQL to add an index to a table
addPrimaryKey()¶
public function addPrimaryKey(
string $tableName,
string $schemaName,
IndexInterface $index
): string;
Generates SQL to add the primary key to a table
createTable()¶
Generates SQL to create a table
createView()¶
public function createView(
string $viewName,
array $definition,
string|null $schemaName = null
): string;
Generates SQL to create a view
describeColumns()¶
Generates SQL describing a table
describeIndex()¶
Generates SQL to query indexes detail on a table
describeIndexes()¶
Generates SQL to query indexes on a table
describeReferences()¶
Generates SQL to query foreign keys on a table
dropCheck()¶
SQLite cannot DROP a CHECK constraint from an existing table.
dropColumn()¶
Generates SQL to delete a column from a table
dropForeignKey()¶
public function dropForeignKey(
string $tableName,
string $schemaName,
string $referenceName
): string;
Generates SQL to delete a foreign key from a table
dropIndex()¶
Generates SQL to delete an index from a table
dropPrimaryKey()¶
Generates SQL to delete primary key from a table
dropTable()¶
public function dropTable(
string $tableName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a table
dropView()¶
public function dropView(
string $viewName,
string|null $schemaName = null,
bool $ifExists = true
): string;
Generates SQL to drop a view
forUpdate()¶
Returns a SQL modified with a FOR UPDATE clause. For SQLite, it returns the original query
getColumnDefinition()¶
Gets the column name in SQLite
listIndexesSql()¶
public function listIndexesSql(
string $tableName,
string|null $schemaName = null,
string|null $keyName = null
): string;
Generates the SQL to get query list of indexes
listTables()¶
List all tables in database
listViews()¶
Generates the SQL to list all views of a schema or user
modifyColumn()¶
public function modifyColumn(
string $tableName,
string $schemaName,
ColumnInterface $column,
ColumnInterface|null $currentColumn = null
): string;
Generates SQL to modify a column in a table
returning()¶
Appends a RETURNING clause to the supplied INSERT/UPDATE/DELETE
statement. SQLite 3.35+.
sharedLock()¶
Returns a SQL modified a shared lock statement. For now this method returns the original query
supportsAlterTable()¶
SQLite cannot modify existing columns or add/drop foreign keys, primary
keys, or check constraints through ALTER TABLE; those operations throw
a dedicated Sqlite*NotSupported exception.
supportsReturning()¶
SQLite (3.35+) supports the RETURNING clause.
tableExists()¶
Generates SQL checking for the existence of a schema.table
tableOptions()¶
Generates the SQL to describe the table creation options
truncateTable()¶
Generates SQL to truncate a table
viewExists()¶
Generates SQL checking for the existence of a schema.view
Db\Dialect\Traits\TextTrait¶
Trait Source on GitHub
Phalcon\Db\Dialect\Traits\TextTrait
Uses Phalcon\Db\Column · Phalcon\Db\Exception · Phalcon\Db\Index · Phalcon\Db\RawValue · Phalcon\Db\Reference
Used by Phalcon\Db\Dialect\Mysql · Phalcon\Db\Dialect\Sqlite
Method Summary¶
protected
string
alter(string $tableName,string|null $schemaName = null)
protected
string
alterTableDrop(string $object,string $item,string $tableName,string $schemaName)
protected
string
checkColumnComment( Column $column )
protected
string
checkColumnFirstAfterPositions( Column $column )
protected
string
checkColumnHasDefault( Column $column )
protected
string
checkColumnIsAutoIncrement( Column $column )
protected
string
checkColumnIsGenerated( Column $column )
Emits the GENERATED ALWAYS AS (...) VIRTUAL|STORED clause. Wraps the
protected
string
checkColumnIsInvisible( Column $column )
Emits the INVISIBLE keyword for MySQL 8.0.23+ invisible columns.
protected
string
checkColumnIsNull( Column $column )
protected
string
checkColumnIsPrimary( Column $column )
protected
string
checkColumnSizeAndScale( Column $column )
Checks if the size and/or scale are present and encloses those values
protected
string
checkColumnUnsigned( Column $column )
Checks if a column is unsigned or not and returns the relevant SQL syntax
protected
string
checkReferenceConstraint( Reference $reference )
protected
string
checkReferenceOnDelete( Reference $reference )
protected
string
checkReferenceOnUpdate( Reference $reference )
protected
string
delimit(string $identifier,string $delimiter = "`")
protected
string
drop( string $type )
protected
string
exists( bool $exists )
protected
string
getExistsSql(string $table,string $viewName,string|null $schemaName)
protected
string
getMysqlSchemaString( string|null $schemaName )
protected
string
getNullString()
protected
array
getTableChecks( array $definition )
Returns the list of CONSTRAINT ... CHECK (...) lines for createTable.
protected
array
getTableColumns( array $definition )
protected
array
getTableIndexes( array $definition )
protected
string
getTableOptions( array $definition )
Generates SQL to add the table creation options
protected
array
getTableReferences( array $definition )
protected
string
wrap( string $identifier )
Methods¶
alter()¶
alterTableDrop()¶
protected function alterTableDrop(
string $object,
string $item,
string $tableName,
string $schemaName
): string;
checkColumnComment()¶
checkColumnFirstAfterPositions()¶
checkColumnHasDefault()¶
checkColumnIsAutoIncrement()¶
checkColumnIsGenerated()¶
Emits the GENERATED ALWAYS AS (...) VIRTUAL|STORED clause. Wraps the shared dialect helper for trait users.
checkColumnIsInvisible()¶
Emits the INVISIBLE keyword for MySQL 8.0.23+ invisible columns. Other dialects override this trait helper to return an empty string.
checkColumnIsNull()¶
checkColumnIsPrimary()¶
checkColumnSizeAndScale()¶
Checks if the size and/or scale are present and encloses those values in parentheses if need be
checkColumnUnsigned()¶
Checks if a column is unsigned or not and returns the relevant SQL syntax
checkReferenceConstraint()¶
checkReferenceOnDelete()¶
checkReferenceOnUpdate()¶
delimit()¶
drop()¶
exists()¶
getExistsSql()¶
protected function getExistsSql(
string $table,
string $viewName,
string|null $schemaName
): string;
getMysqlSchemaString()¶
getNullString()¶
getTableChecks()¶
Returns the list of CONSTRAINT ... CHECK (...) lines for createTable. Uses the dialect's escape character via the shared getCheckClause() helper.
getTableColumns()¶
getTableIndexes()¶
getTableOptions()¶
Generates SQL to add the table creation options
getTableReferences()¶
wrap()¶
Db\Enum¶
Class Source on GitHub
Constants for Phalcon\Db
Phalcon\Db\Enum
Uses PDO
Constants¶
mixed
FETCH_ASSOC = PDO::FETCH_ASSOC
mixed
FETCH_BOTH = PDO::FETCH_BOTH
mixed
FETCH_BOUND = PDO::FETCH_BOUND
mixed
FETCH_CLASS = PDO::FETCH_CLASS
mixed
FETCH_CLASSTYPE = PDO::FETCH_CLASSTYPE
mixed
FETCH_COLUMN = PDO::FETCH_COLUMN
mixed
FETCH_DEFAULT = PDO::FETCH_DEFAULT
mixed
FETCH_FUNC = PDO::FETCH_FUNC
mixed
FETCH_GROUP = PDO::FETCH_GROUP
mixed
FETCH_INTO = PDO::FETCH_INTO
mixed
FETCH_KEY_PAIR = PDO::FETCH_KEY_PAIR
mixed
FETCH_LAZY = PDO::FETCH_LAZY
mixed
FETCH_NAMED = PDO::FETCH_NAMED
mixed
FETCH_NUM = PDO::FETCH_NUM
mixed
FETCH_OBJ = PDO::FETCH_OBJ
mixed
FETCH_ORI_NEXT = PDO::FETCH_ORI_NEXT
mixed
FETCH_PROPS_LATE = PDO::FETCH_PROPS_LATE
mixed
FETCH_SERIALIZE = PDO::FETCH_SERIALIZE
mixed
FETCH_UNIQUE = PDO::FETCH_UNIQUE
Db\Event\AbstractCancellableModelEvent¶
Abstract Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEvent- implements\Psr\EventDispatcher\StoppableEventInterfacePhalcon\Db\Event\AfterValidationEventPhalcon\Db\Event\AfterValidationOnCreateEventPhalcon\Db\Event\AfterValidationOnUpdateEventPhalcon\Db\Event\BeforeCreateEventPhalcon\Db\Event\BeforeDeleteEventPhalcon\Db\Event\BeforeSaveEventPhalcon\Db\Event\BeforeUpdateEventPhalcon\Db\Event\BeforeValidationEventPhalcon\Db\Event\BeforeValidationOnCreateEventPhalcon\Db\Event\BeforeValidationOnUpdateEventPhalcon\Db\Event\ValidationEvent
Uses Psr\EventDispatcher\StoppableEventInterface
Method Summary¶
Methods¶
cancel()¶
isPropagationStopped()¶
Db\Event\AbstractModelEvent¶
Abstract Source on GitHub
Phalcon\Db\Event\AbstractModelEvent- implementsPhalcon\Events\PsrEventInterfacePhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\AfterCreateEventPhalcon\Db\Event\AfterDeleteEventPhalcon\Db\Event\AfterFetchEventPhalcon\Db\Event\AfterSaveEventPhalcon\Db\Event\AfterUpdateEventPhalcon\Db\Event\NotDeletedEventPhalcon\Db\Event\NotSavedEventPhalcon\Db\Event\OnValidationFailsEventPhalcon\Db\Event\PrepareSaveEvent
Uses Phalcon\Events\PsrEventInterface · Phalcon\Mvc\Model
Method Summary¶
Properties¶
public
Model
$model
Methods¶
__construct()¶
Db\Event\AfterCreateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AfterCreateEvent
Db\Event\AfterDeleteEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AfterDeleteEvent
Db\Event\AfterFetchEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AfterFetchEvent
Db\Event\AfterSaveEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AfterSaveEvent
Db\Event\AfterUpdateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AfterUpdateEvent
Db\Event\AfterValidationEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\AfterValidationEvent
Db\Event\AfterValidationOnCreateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\AfterValidationOnCreateEvent
Db\Event\AfterValidationOnUpdateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\AfterValidationOnUpdateEvent
Db\Event\BeforeCreateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeCreateEvent
Db\Event\BeforeDeleteEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeDeleteEvent
Db\Event\BeforeSaveEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeSaveEvent
Db\Event\BeforeUpdateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeUpdateEvent
Db\Event\BeforeValidationEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeValidationEvent
Db\Event\BeforeValidationOnCreateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeValidationOnCreateEvent
Db\Event\BeforeValidationOnUpdateEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\BeforeValidationOnUpdateEvent
Db\Event\Factory¶
Class Source on GitHub
Phalcon\Db\Event\Factory
Uses Phalcon\Events\PsrEventInterface · Phalcon\Mvc\Model
Method Summary¶
Methods¶
create()¶
Db\Event\ModelEventNameEnum¶
Class Source on GitHub
Phalcon\Db\Event\ModelEventNameEnum
Method Summary¶
public
self
fromEventClass( string $eventClassName )
Get an enum case from event class name
public
string
getEventClass( mixed $eventName )
Get the event class associated with this event type
public
self|null
tryFromEventClass( string $eventClassName )
Constants¶
string
AFTER_CREATE = "afterCreate"
string
AFTER_DELETE = "afterDelete"
string
AFTER_FETCH = "afterFetch"
string
AFTER_SAVE = "afterSave"
string
AFTER_UPDATE = "afterUpdate"
string
AFTER_VALIDATION = "afterValidation"
string
AFTER_VALIDATION_ON_CREATE = "afterValidationOnCreate"
string
AFTER_VALIDATION_ON_UPDATE = "afterValidationOnUpdate"
string
BEFORE_CREATE = "beforeCreate"
string
BEFORE_DELETE = "beforeDelete"
string
BEFORE_SAVE = "beforeSave"
string
BEFORE_UPDATE = "beforeUpdate"
string
BEFORE_VALIDATION = "beforeValidation"
string
BEFORE_VALIDATION_ON_CREATE = "beforeValidationOnCreate"
string
BEFORE_VALIDATION_ON_UPDATE = "beforeValidationOnUpdate"
string
NOT_DELETED = "notDeleted"
string
NOT_SAVED = "notSaved"
string
ON_VALIDATION_FAILS = "onValidationFails"
string
PREPARE_SAVE = "prepareSave"
string
VALIDATION = "validation"
Methods¶
fromEventClass()¶
Get an enum case from event class name
getEventClass()¶
Get the event class associated with this event type
tryFromEventClass()¶
Db\Event\NotDeletedEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\NotDeletedEvent
Db\Event\NotSavedEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\NotSavedEvent
Db\Event\OnValidationFailsEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\OnValidationFailsEvent
Db\Event\PrepareSaveEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\PrepareSaveEvent
Db\Event\UnknownEventTypeException¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Event\UnknownEventTypeException
Uses Phalcon\Db\Exception · Throwable
Method Summary¶
Methods¶
__construct()¶
public function __construct(
string $message = "",
int $code = 0,
Throwable|null $previous = null
);
Db\Event\ValidationEvent¶
Class Source on GitHub
Phalcon\Db\Event\AbstractModelEventPhalcon\Db\Event\AbstractCancellableModelEventPhalcon\Db\Event\ValidationEvent
Db\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Db will use this class
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Event\UnknownEventTypeExceptionPhalcon\Db\Exceptions\CannotInsertWithoutDataPhalcon\Db\Exceptions\CannotPrepareStatementPhalcon\Db\Exceptions\CheckExpressionRequiredPhalcon\Db\Exceptions\ColumnTypeRejectsAutoIncrementPhalcon\Db\Exceptions\ColumnTypeRejectsScalePhalcon\Db\Exceptions\ColumnTypeRequiredPhalcon\Db\Exceptions\ConflictTargetColumnRequiredPhalcon\Db\Exceptions\ConflictUpdateColumnRequiredPhalcon\Db\Exceptions\ForeignKeyColumnsRequiredPhalcon\Db\Exceptions\GeneratedAutoIncrementConflictPhalcon\Db\Exceptions\GeneratedDefaultConflictPhalcon\Db\Exceptions\IncompleteBindTypesPhalcon\Db\Exceptions\InvalidBindParameterPhalcon\Db\Exceptions\InvalidCheckExpressionPhalcon\Db\Exceptions\InvalidDialectClassPhalcon\Db\Exceptions\InvalidGenerationExpressionPhalcon\Db\Exceptions\InvalidGroupByExpressionPhalcon\Db\Exceptions\InvalidIndexColumnsPhalcon\Db\Exceptions\InvalidIndexDirectionsPhalcon\Db\Exceptions\InvalidIndexWherePhalcon\Db\Exceptions\InvalidListExpressionPhalcon\Db\Exceptions\InvalidOrderByExpressionPhalcon\Db\Exceptions\InvalidSqlExpressionPhalcon\Db\Exceptions\InvalidSqlExpressionTypePhalcon\Db\Exceptions\InvalidUnaryExpressionPhalcon\Db\Exceptions\InvalidWhereConditionsPhalcon\Db\Exceptions\InvalidWkbPhalcon\Db\Exceptions\MatchedParameterNotFoundPhalcon\Db\Exceptions\MaterializedViewsNotSupportedPhalcon\Db\Exceptions\MissingDefinitionKeyPhalcon\Db\Exceptions\MissingForeignKeyChecksPhalcon\Db\Exceptions\MissingSqliteDatabasePhalcon\Db\Exceptions\MysqlOnConflictNotSupportedPhalcon\Db\Exceptions\NestedTransactionChangeBlockedPhalcon\Db\Exceptions\NoActiveTransactionPhalcon\Db\Exceptions\ReferencedColumnCountMismatchPhalcon\Db\Exceptions\ReferencedColumnsRequiredPhalcon\Db\Exceptions\ReferencedTableRequiredPhalcon\Db\Exceptions\ReturningNotSupportedPhalcon\Db\Exceptions\ReturningRequiresColumnPhalcon\Db\Exceptions\SavepointsNotSupportedPhalcon\Db\Exceptions\SqliteAlterCheckNotSupportedPhalcon\Db\Exceptions\SqliteAlterColumnNotSupportedPhalcon\Db\Exceptions\SqliteAlterForeignKeyNotSupportedPhalcon\Db\Exceptions\SqliteAlterPrimaryKeyNotSupportedPhalcon\Db\Exceptions\SqliteDropCheckNotSupportedPhalcon\Db\Exceptions\SqliteDropForeignKeyNotSupportedPhalcon\Db\Exceptions\SqliteDropPrimaryKeyNotSupportedPhalcon\Db\Exceptions\TableMustHaveColumnPhalcon\Db\Exceptions\UnrecognizedDataTypePhalcon\Db\Exceptions\UnsupportedOperatorPhalcon\Db\Exceptions\UpdateFieldCountMismatch
Db\Exceptions\CannotInsertWithoutData¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\CannotInsertWithoutData
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\CannotPrepareStatement¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\CannotPrepareStatement
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\CheckExpressionRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\CheckExpressionRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ColumnTypeRejectsAutoIncrement¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ColumnTypeRejectsAutoIncrement
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ColumnTypeRejectsScale¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ColumnTypeRejectsScale
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ColumnTypeRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ColumnTypeRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ConflictTargetColumnRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ConflictTargetColumnRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ConflictUpdateColumnRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ConflictUpdateColumnRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ForeignKeyColumnsRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ForeignKeyColumnsRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\GeneratedAutoIncrementConflict¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\GeneratedAutoIncrementConflict
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\GeneratedDefaultConflict¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\GeneratedDefaultConflict
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\IncompleteBindTypes¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\IncompleteBindTypes
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidBindParameter¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidBindParameter
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidCheckExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidCheckExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidDialectClass¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidDialectClass
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidGenerationExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidGenerationExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidGroupByExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidGroupByExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidIndexColumns¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidIndexColumns
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidIndexDirections¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidIndexDirections
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidIndexWhere¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidIndexWhere
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidListExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidListExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidOrderByExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidOrderByExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidSqlExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidSqlExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidSqlExpressionType¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidSqlExpressionType
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidUnaryExpression¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidUnaryExpression
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidWhereConditions¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidWhereConditions
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\InvalidWkb¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\InvalidWkb
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MatchedParameterNotFound¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MatchedParameterNotFound
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MaterializedViewsNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MaterializedViewsNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MissingDefinitionKey¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MissingDefinitionKey
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MissingForeignKeyChecks¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MissingForeignKeyChecks
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MissingSqliteDatabase¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MissingSqliteDatabase
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\MysqlOnConflictNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\MysqlOnConflictNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\NestedTransactionChangeBlocked¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\NestedTransactionChangeBlocked
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\NoActiveTransaction¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\NoActiveTransaction
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ReferencedColumnCountMismatch¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ReferencedColumnCountMismatch
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ReferencedColumnsRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ReferencedColumnsRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ReferencedTableRequired¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ReferencedTableRequired
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ReturningNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ReturningNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\ReturningRequiresColumn¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\ReturningRequiresColumn
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SavepointsNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SavepointsNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteAlterCheckNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteAlterCheckNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteAlterColumnNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteAlterColumnNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteAlterForeignKeyNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteAlterForeignKeyNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteAlterPrimaryKeyNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteAlterPrimaryKeyNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteDropCheckNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteDropCheckNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteDropForeignKeyNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteDropForeignKeyNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\SqliteDropPrimaryKeyNotSupported¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\SqliteDropPrimaryKeyNotSupported
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\TableMustHaveColumn¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\TableMustHaveColumn
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\UnrecognizedDataType¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\UnrecognizedDataType
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\UnsupportedOperator¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\UnsupportedOperator
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Exceptions\UpdateFieldCountMismatch¶
Class Source on GitHub
\ExceptionPhalcon\Db\ExceptionPhalcon\Db\Exceptions\UpdateFieldCountMismatch
Uses Phalcon\Db\Exception
Method Summary¶
Methods¶
__construct()¶
Db\Geometry\AbstractGeometry¶
Abstract Source on GitHub
Phalcon\Db\Geometry\AbstractGeometry- implementsPhalcon\Db\Geometry\GeometryInterface
Method Summary¶
Properties¶
protected
int
$srid = 0
Methods¶
__toString()¶
getSrid()¶
getType()¶
toWkt()¶
Db\Geometry\GeometryCollection¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\GeometryCollection
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $geometries,int $srid = 0)
public
array
getGeometries()
public
int
getType()
public
string
toWkt()
Properties¶
protected
GeometryInterface[]
$geometries
Methods¶
__construct()¶
getGeometries()¶
getType()¶
toWkt()¶
Db\Geometry\GeometryInterface¶
Interface Source on GitHub
Phalcon\Db\Geometry\GeometryInterface
Phalcon\Contracts\Db\Geometry\GeometryPhalcon\Db\Geometry\GeometryInterface
Uses Phalcon\Contracts\Db\Geometry\Geometry
Db\Geometry\LineString¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\LineString
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $points,int $srid = 0)
public
array
getPoints()
public
int
getType()
public
string
pointsWkt()
public
string
toWkt()
Properties¶
protected
Point[]
$points
Methods¶
__construct()¶
getPoints()¶
getType()¶
pointsWkt()¶
toWkt()¶
Db\Geometry\MultiLineString¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\MultiLineString
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $lineStrings,int $srid = 0)
public
array
getLineStrings()
public
int
getType()
public
string
toWkt()
Properties¶
protected
LineString[]
$lineStrings
Methods¶
__construct()¶
getLineStrings()¶
getType()¶
toWkt()¶
Db\Geometry\MultiPoint¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\MultiPoint
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $points,int $srid = 0)
public
array
getPoints()
public
int
getType()
public
string
toWkt()
Properties¶
protected
Point[]
$points
Methods¶
__construct()¶
getPoints()¶
getType()¶
toWkt()¶
Db\Geometry\MultiPolygon¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\MultiPolygon
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $polygons,int $srid = 0)
public
array
getPolygons()
public
int
getType()
public
string
toWkt()
Properties¶
protected
Polygon[]
$polygons
Methods¶
__construct()¶
getPolygons()¶
getType()¶
toWkt()¶
Db\Geometry\Point¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\Point
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(float $x,float $y,int $srid = 0)
public
string
coordsWkt()
public
int
getType()
public
float
getX()
public
float
getY()
public
string
toWkt()
Properties¶
protected
float
$x
protected
float
$y
Methods¶
__construct()¶
coordsWkt()¶
getType()¶
getX()¶
getY()¶
toWkt()¶
Db\Geometry\Polygon¶
Class Source on GitHub
Phalcon\Db\Geometry\AbstractGeometryPhalcon\Db\Geometry\Polygon
Uses Phalcon\Db\Column
Method Summary¶
public
__construct(array $rings,int $srid = 0)
public
array
getRings()
public
int
getType()
public
string
ringsWkt()
public
string
toWkt()
Properties¶
protected
Point[][]
$rings
Methods¶
__construct()¶
getRings()¶
getType()¶
ringsWkt()¶
toWkt()¶
Db\Geometry\WkbParser¶
Class Source on GitHub
Decodes a spatial column value into a geometry value object.
Handles MySQL's internal format (4-byte little-endian SRID prefix followed by standard OGC WKB) and PostGIS EWKB returned as a hex string. 2D only: any Z/M ordinates are read past and discarded.
Phalcon\Db\Geometry\WkbParser
Uses Phalcon\Db\Exceptions\InvalidWkb
Method Summary¶
public
GeometryInterface
parse( string $raw )
protected
int
readByte()
protected
float
readDouble( bool $little )
protected
GeometryInterface
readGeometry( int $outerSrid )
protected
Point
readPoint(bool $little,bool $hasZ,bool $hasM,int $srid)
protected
array
readPointList(bool $little,bool $hasZ,bool $hasM)
protected
array
readRingList(bool $little,bool $hasZ,bool $hasM)
protected
int
readUint32( bool $little )
protected
void
skipExtraOrdinates(bool $little,bool $hasZ,bool $hasM)
Properties¶
protected
string
$buffer = ""
protected
int
$length = 0
protected
int
$position = 0
Methods¶
parse()¶
readByte()¶
readDouble()¶
readGeometry()¶
readPoint()¶
readPointList()¶
readRingList()¶
readUint32()¶
skipExtraOrdinates()¶
Db\Index¶
Class Source on GitHub
Allows to define indexes to be used on tables. Indexes are a common way to enhance database performance. An index allows the database server to find and retrieve specific rows much faster than it could do without an index.
The constructor accepts either the legacy positional form (a plain array
of column names) or a definition-array form (an associative array with a
columns key); the latter is the path used by features such as
invisible (MySQL 8.0+), directions, where, and concurrently.
// Legacy positional form
$unique = new \Phalcon\Db\Index(
'column_UNIQUE',
[
'column',
],
'UNIQUE'
);
$primary = new \Phalcon\Db\Index(
'PRIMARY',
[
'column',
]
);
// Definition-array form (MySQL 8.0+ invisible index)
$hidden = new \Phalcon\Db\Index(
'idx_hidden',
[
'columns' => ['col1'],
'type' => '',
'invisible' => true,
'directions' => ['DESC'],
]
);
Phalcon\Db\Index- implementsPhalcon\Db\IndexInterface
Uses Phalcon\Db\Exceptions\InvalidIndexColumns · Phalcon\Db\Exceptions\InvalidIndexDirections · Phalcon\Db\Exceptions\InvalidIndexWhere
Method Summary¶
public
__construct(string $name,array $columnsOrDefinition,string $type = "")
Phalcon\Db\Index constructor.
public
array
getColumns()
Index columns
public
array
getDirections()
Returns the per-column sort directions array (ASC / DESC).
public
string
getName()
Index name
public
string
getType()
Index type
public
string
getWhere()
Returns the partial-index WHERE predicate, or an empty string when
public
bool
isConcurrent()
Whether the index is built CONCURRENTLY (PostgreSQL only).
public
bool
isInvisible()
Whether the index is declared INVISIBLE (MySQL 8.0+).
Properties¶
protected
array
$columns
Index columns. Entries may be plain strings (column names) or
Phalcon\Db\RawValue instances (functional/expression index entries).
protected
bool
$concurrent = false
Whether to build the index without taking a strong lock that blocks
writes - emits CONCURRENTLY between INDEX and the index name on
PostgreSQL. MySQL and SQLite ignore the flag.
protected
array
$directions = []
Per-column sort directions (ASC / DESC). Empty array means
"emit no per-column direction" - preserves the legacy plain
(col1, col2) rendering.
protected
bool
$invisible = false
Whether the index is declared INVISIBLE (MySQL 8.0+).
protected
string
$name
protected
string
$type = ""
protected
string
$where = ""
Optional partial-index WHERE predicate. Supported by PostgreSQL and
SQLite. Empty string means no predicate.
Methods¶
__construct()¶
Phalcon\Db\Index constructor.
Accepts either the legacy positional form (name, columns, type) or
a definition-array form (name, ["columns" => [...], "type" => "...",
"invisible" => true, ...]). Detection is based on the presence of a
columns key in the second argument; when present, the third
positional type argument is ignored in favor of the definition.
getColumns()¶
Index columns
getDirections()¶
Returns the per-column sort directions array (ASC / DESC).
Empty array means the index was declared without explicit per-column
directions.
getName()¶
Index name
getType()¶
Index type
getWhere()¶
Returns the partial-index WHERE predicate, or an empty string when
the index has none.
isConcurrent()¶
Whether the index is built CONCURRENTLY (PostgreSQL only).
isInvisible()¶
Whether the index is declared INVISIBLE (MySQL 8.0+).
Db\IndexInterface¶
Interface Source on GitHub
Phalcon\Db\IndexInterface
Phalcon\Contracts\Db\IndexPhalcon\Db\IndexInterface
Uses Phalcon\Contracts\Db\Index
Db\Profiler¶
Class Source on GitHub
Instances of Phalcon\Db can generate execution profiles on SQL statements sent to the relational database. Profiled information includes execution time in milliseconds. This helps you to identify bottlenecks in your applications.
use Phalcon\Db\Profiler;
use Phalcon\Events\Event;
use Phalcon\Events\Manager;
$profiler = new Profiler();
$eventsManager = new Manager();
$eventsManager->attach(
"db",
function (Event $event, $connection) use ($profiler) {
if ($event->getType() === "beforeQuery") {
$sql = $connection->getSQLStatement();
// Start a profile with the active connection
$profiler->startProfile($sql);
}
if ($event->getType() === "afterQuery") {
// Stop the active profile
$profiler->stopProfile();
}
}
);
// Set the event manager on the connection
$connection->setEventsManager($eventsManager);
$sql = "SELECT buyer_name, quantity, product_name
FROM buyers LEFT JOIN products ON
buyers.pid=products.id";
// Execute a SQL statement
$connection->query($sql);
// Get the last profile in the profiler
$profile = $profiler->getLastProfile();
echo "SQL Statement: ", $profile->getSQLStatement(), "\n";
echo "Start Time: ", $profile->getInitialTime(), "\n";
echo "Final Time: ", $profile->getFinalTime(), "\n";
echo "Total Elapsed Time: ", $profile->getTotalElapsedSeconds(), "\n";
Phalcon\Db\Profiler
Uses Phalcon\Db\Profiler\Item · Phalcon\Db\Traits\ElapsedTimeTrait
Method Summary¶
public
Item|null
getLastProfile()
Returns the last profile executed in the profiler
public
int
getMaxProfiles()
Returns the configured maximum number of retained profiles
public
int
getNumberTotalStatements()
Returns the total number of SQL statements processed
public
array
getProfiles()
Returns all the processed profiles
public
float
getTotalElapsedNanoseconds()
Returns the total time in nanoseconds spent by the profiles
public
static
reset()
Resets the profiler, cleaning up all the profiles
public
static
setMaxProfiles( int $maxProfiles )
Sets the maximum number of retained profiles. 0 disables the cap
public
static
startProfile(string $sqlStatement,array $sqlVariables = [],array $sqlBindTypes = [])
Starts the profile of a SQL sentence
public
static
stopProfile()
Stops the active profile
Properties¶
protected
Item|null
$activeProfile = null
Active Item
protected
Item[]
$allProfiles = []
All the Items in the active profile
protected
int
$maxProfiles = 0
Maximum number of profiles to retain. 0 (default) keeps the
original unbounded behavior; a positive value drops the oldest
profile FIFO before a new one is appended.
protected
float
$totalNanoseconds = 0
Total time spent by all profiles to complete in nanoseconds
Methods¶
getLastProfile()¶
Returns the last profile executed in the profiler
getMaxProfiles()¶
Returns the configured maximum number of retained profiles (0 = unlimited)
getNumberTotalStatements()¶
Returns the total number of SQL statements processed
getProfiles()¶
Returns all the processed profiles
getTotalElapsedNanoseconds()¶
Returns the total time in nanoseconds spent by the profiles
reset()¶
Resets the profiler, cleaning up all the profiles
setMaxProfiles()¶
Sets the maximum number of retained profiles. 0 disables the cap (the default; preserves the original unbounded behavior).
startProfile()¶
public function startProfile(
string $sqlStatement,
array $sqlVariables = [],
array $sqlBindTypes = []
): static;
Starts the profile of a SQL sentence
stopProfile()¶
Stops the active profile
Db\Profiler\Item¶
Class Source on GitHub
This class identifies each profile in a Phalcon\Db\Profiler
Phalcon\Db\Profiler\Item
Uses Phalcon\Db\Traits\ElapsedTimeTrait
Method Summary¶
public
float
getFinalTime()
Return the timestamp when the profile ended
public
float
getInitialTime()
Return the timestamp when the profile started
public
array
getSqlBindTypes()
Return the SQL bind types related to the profile
public
string
getSqlStatement()
Return the SQL statement related to the profile
public
array
getSqlVariables()
Return the SQL variables related to the profile
public
float
getTotalElapsedNanoseconds()
Returns the total time in nanoseconds spent by the profile
public
static
setFinalTime( float $finalTime )
Return the timestamp when the profile ended
public
static
setInitialTime( float $initialTime )
Return the timestamp when the profile started
public
static
setSqlBindTypes( array $sqlBindTypes )
Return the SQL bind types related to the profile
public
static
setSqlStatement( string $sqlStatement )
Return the SQL statement related to the profile
public
static
setSqlVariables( array $sqlVariables )
Return the SQL variables related to the profile
Properties¶
protected
float
$finalTime
Timestamp when the profile ended
protected
float
$initialTime
Timestamp when the profile started
protected
array
$sqlBindTypes
SQL bind types related to the profile
protected
string
$sqlStatement
SQL statement related to the profile
protected
array
$sqlVariables
SQL variables related to the profile
Methods¶
getFinalTime()¶
Return the timestamp when the profile ended
getInitialTime()¶
Return the timestamp when the profile started
getSqlBindTypes()¶
Return the SQL bind types related to the profile
getSqlStatement()¶
Return the SQL statement related to the profile
getSqlVariables()¶
Return the SQL variables related to the profile
getTotalElapsedNanoseconds()¶
Returns the total time in nanoseconds spent by the profile
setFinalTime()¶
Return the timestamp when the profile ended
setInitialTime()¶
Return the timestamp when the profile started
setSqlBindTypes()¶
Return the SQL bind types related to the profile
setSqlStatement()¶
Return the SQL statement related to the profile
setSqlVariables()¶
Return the SQL variables related to the profile
Db\RawValue¶
Class Source on GitHub
This class allows to insert/update raw data without quoting or formatting.
The next example shows how to use the MySQL now() function as a field value.
$subscriber = new Subscribers();
$subscriber->email = "[email protected]";
$subscriber->createdAt = new \Phalcon\Db\RawValue("now()");
$subscriber->save();
Phalcon\Db\RawValue
Method Summary¶
public
__construct( mixed $value = null )
Phalcon\Db\RawValue constructor
public
string
__toString()
public
string
getValue()
Properties¶
protected
string
$value
Raw value without quoting or formatting
Methods¶
__construct()¶
Phalcon\Db\RawValue constructor
__toString()¶
getValue()¶
Db\Reference¶
Class Source on GitHub
Allows to define reference constraints on tables
$reference = new \Phalcon\Db\Reference(
"field_fk",
[
"referencedSchema" => "invoicing",
"referencedTable" => "products",
"columns" => [
"producttype",
"product_code",
],
"referencedColumns" => [
"type",
"code",
],
]
);
Phalcon\Db\Reference- implementsPhalcon\Db\ReferenceInterface
Uses Phalcon\Db\Exceptions\ForeignKeyColumnsRequired · Phalcon\Db\Exceptions\ReferencedColumnCountMismatch · Phalcon\Db\Exceptions\ReferencedColumnsRequired · Phalcon\Db\Exceptions\ReferencedTableRequired
Method Summary¶
public
__construct(string $name,array $definition)
Phalcon\Db\Reference constructor
public
array
getColumns()
Local reference columns
public
string
getName()
Constraint name
public
string|null
getOnDelete()
ON DELETE
public
string|null
getOnUpdate()
ON UPDATE
public
array
getReferencedColumns()
Referenced Columns
public
string|null
getReferencedSchema()
Referenced Schema
public
string
getReferencedTable()
Referenced Table
public
string|null
getSchemaName()
Schema name
Properties¶
protected
array
$columns
Local reference columns
protected
string
$name
protected
string|null
$onDelete = null
ON DELETE
protected
string|null
$onUpdate = null
ON UPDATE
protected
array
$referencedColumns
Referenced Columns
protected
string|null
$referencedSchema = null
Referenced Schema
protected
string
$referencedTable
Referenced Table
protected
string|null
$schemaName = null
Schema name
Methods¶
__construct()¶
Phalcon\Db\Reference constructor
getColumns()¶
Local reference columns
getName()¶
Constraint name
getOnDelete()¶
ON DELETE
getOnUpdate()¶
ON UPDATE
getReferencedColumns()¶
Referenced Columns
getReferencedSchema()¶
Referenced Schema
getReferencedTable()¶
Referenced Table
getSchemaName()¶
Schema name
Db\ReferenceInterface¶
Interface Source on GitHub
Phalcon\Db\ReferenceInterface
Phalcon\Contracts\Db\ReferencePhalcon\Db\ReferenceInterface
Uses Phalcon\Contracts\Db\Reference
Db\ResultInterface¶
Interface Source on GitHub
Phalcon\Db\ResultInterface
Phalcon\Contracts\Db\ResultPhalcon\Db\ResultInterface
Uses Phalcon\Contracts\Db\Result
Db\Result\PdoResult¶
Class Source on GitHub
Encapsulates the resultset internals
$result = $connection->query("SELECT * FROM co_invoices ORDER BY inv_title");
$result->setFetchMode(
\Phalcon\Db\Enum::FETCH_NUM
);
while ($invoice = $result->fetchArray()) {
print_r($invoice);
}
Phalcon\Db\Result\PdoResult- implementsPhalcon\Db\ResultInterface
Uses PDOStatement · Phalcon\Db\Adapter\AdapterInterface · Phalcon\Db\Enum · Phalcon\Db\ResultInterface
Method Summary¶
public
__construct(AdapterInterface $connection,PDOStatement $pdoStatement,string $sqlStatement = "",array $bindParams = [],array $bindTypes = [])
Phalcon\Db\Result\Pdo constructor
public
void
dataSeek( int $number )
Moves internal resultset cursor to another position letting us to fetch a
public
bool
execute()
Allows to execute the statement again. Some database systems don't
public
mixed
fetch(int|null $fetchStyle = null,int $cursorOrientation = Enum::FETCH_ORI_NEXT,int $cursorOffset = 0)
Fetches an array/object of strings that corresponds to the fetched row,
public
array
fetchAll(int $mode = Enum::FETCH_DEFAULT,mixed $fetchArgument = Enum::FETCH_ORI_NEXT,array|null $constructorArgs = null)
Returns an array of arrays containing all the records in the result
public
mixed
fetchArray()
Returns an array of strings that corresponds to the fetched row, or FALSE
public
PDOStatement
getInternalResult()
Gets the internal PDO result object
public
int
numRows()
Gets number of rows returned by a resultset
public
bool
setFetchMode(int $fetchMode,object|string|null $colNoOrClassNameOrObject = null,mixed $ctorargs = null)
Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch()
Properties¶
protected
array
$bindParams = []
protected
array
$bindTypes = []
protected
AdapterInterface
$connection
protected
int
$fetchMode = Enum::FETCH_DEFAULT
Active fetch mode
protected
PDOStatement
$pdoStatement
protected
mixed
$result
protected
int|null
$rowCount = null
protected
string
$sqlStatement = ""
Methods¶
__construct()¶
public function __construct(
AdapterInterface $connection,
PDOStatement $pdoStatement,
string $sqlStatement = "",
array $bindParams = [],
array $bindTypes = []
);
Phalcon\Db\Result\Pdo constructor
dataSeek()¶
Moves internal resultset cursor to another position letting us to fetch a certain row
$result = $connection->query(
"SELECT * FROM co_invoices ORDER BY inv_title"
);
// Move to third row on result
$result->dataSeek(2);
// Fetch third row
$row = $result->fetch();
execute()¶
Allows to execute the statement again. Some database systems don't support scrollable cursors. So, as cursors are forward only, we need to execute the cursor again to fetch rows from the beginning
fetch()¶
public function fetch(
int|null $fetchStyle = null,
int $cursorOrientation = Enum::FETCH_ORI_NEXT,
int $cursorOffset = 0
): mixed;
Fetches an array/object of strings that corresponds to the fetched row,
or FALSE if there are no more rows. This method is affected by the active
fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode()
$result = $connection->query("SELECT * FROM co_invoices ORDER BY inv_title");
$result->setFetchMode(
\Phalcon\Enum::FETCH_OBJ
);
while ($invoice = $result->fetch()) {
echo $invoice->inv_title;
}
fetchAll()¶
public function fetchAll(
int $mode = Enum::FETCH_DEFAULT,
mixed $fetchArgument = Enum::FETCH_ORI_NEXT,
array|null $constructorArgs = null
): array;
Returns an array of arrays containing all the records in the result
This method is affected by the active fetch flag set using
Phalcon\Db\Result\Pdo::setFetchMode()
$result = $connection->query(
"SELECT * FROM co_invoices ORDER BY inv_title"
);
$invoices = $result->fetchAll();
fetchArray()¶
Returns an array of strings that corresponds to the fetched row, or FALSE
if there are no more rows. This method is affected by the active fetch
flag set using Phalcon\Db\Result\Pdo::setFetchMode()
$result = $connection->query("SELECT * FROM co_invoices ORDER BY inv_title");
$result->setFetchMode(
\Phalcon\Enum::FETCH_NUM
);
while ($invoice = result->fetchArray()) {
print_r($invoice);
}
getInternalResult()¶
Gets the internal PDO result object
numRows()¶
Gets number of rows returned by a resultset
$result = $connection->query(
"SELECT * FROM co_invoices ORDER BY inv_title"
);
echo "There are ", $result->numRows(), " rows in the resultset";
setFetchMode()¶
public function setFetchMode(
int $fetchMode,
object|string|null $colNoOrClassNameOrObject = null,
mixed $ctorargs = null
): bool;
Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch()
// Return array with integer indexes
$result->setFetchMode(
\Phalcon\Enum::FETCH_NUM
);
// Return associative array without integer indexes
$result->setFetchMode(
\Phalcon\Enum::FETCH_ASSOC
);
// Return associative array together with integer indexes
$result->setFetchMode(
\Phalcon\Enum::FETCH_BOTH
);
// Return an object
$result->setFetchMode(
\Phalcon\Enum::FETCH_OBJ
);
Db\Traits\ElapsedTimeTrait¶
Trait Source on GitHub
Derives elapsed milliseconds and seconds from the nanosecond total that the using class exposes through getTotalElapsedNanoseconds().
Phalcon\Db\Traits\ElapsedTimeTrait
Used by Phalcon\Db\Profiler · Phalcon\Db\Profiler\Item
Method Summary¶
public
float
getTotalElapsedMilliseconds()
Returns the total time in milliseconds spent by the profiles
public
float
getTotalElapsedNanoseconds()
Returns the total time in nanoseconds spent by the profiles. Implemented
public
float
getTotalElapsedSeconds()
Returns the total time in seconds spent by the profiles
Methods¶
getTotalElapsedMilliseconds()¶
Returns the total time in milliseconds spent by the profiles
getTotalElapsedNanoseconds()¶
Returns the total time in nanoseconds spent by the profiles. Implemented by the using class.
getTotalElapsedSeconds()¶
Returns the total time in seconds spent by the profiles