Abstract class **Phalcon\\Db\\Adapter** ======================================= *implements* :doc:`Phalcon\\Db\\AdapterInterface `, :doc:`Phalcon\\Events\\EventsAwareInterface ` .. role:: raw-html(raw) :format: html :raw-html:`Source on GitHub` Base class for Phalcon\\Db adapters Methods ------- public **getDialectType** () Name of the dialect used public **getType** () Type of database system the adapter is used for public **getSqlVariables** () Active SQL bound parameter variables public **__construct** (*array* $descriptor) Phalcon\\Db\\Adapter constructor public **setEventsManager** (:doc:`Phalcon\\Events\\ManagerInterface ` $eventsManager) Sets the event manager public **getEventsManager** () Returns the internal event manager public **setDialect** (:doc:`Phalcon\\Db\\DialectInterface ` $dialect) Sets the dialect used to produce the SQL public **getDialect** () Returns internal dialect instance public **fetchOne** (*mixed* $sqlQuery, [*mixed* $fetchMode], [*mixed* $bindParams], [*mixed* $bindTypes]) Returns the first row in a SQL query result .. code-block:: php fetchOne("SELECT * FROM robots"); print_r($robot); // Getting first robot with associative indexes only $robot = $connection->fetchOne("SELECT * FROM robots", \Phalcon\Db::FETCH_ASSOC); print_r($robot); public *array* **fetchAll** (*string* $sqlQuery, [*int* $fetchMode], [*array* $bindParams], [*array* $bindTypes]) Dumps the complete result of a query into an array .. code-block:: php fetchAll( "SELECT * FROM robots", \Phalcon\Db::FETCH_ASSOC ); foreach ($robots as $robot) { print_r($robot); } // Getting all robots that contains word "robot" withing the name $robots = $connection->fetchAll( "SELECT * FROM robots WHERE name LIKE :name", \Phalcon\Db::FETCH_ASSOC, [ "name" => "%robot%", ] ); foreach($robots as $robot) { print_r($robot); } public *string* | ** **fetchColumn** (*string* $sqlQuery, [*array* $placeholders], [*int* | *string* $column]) Returns the n'th field of first row in a SQL query result .. code-block:: php fetchColumn("SELECT count(*) FROM robots"); print_r($robotsCount); // Getting name of last edited robot $robot = $connection->fetchColumn( "SELECT id, name FROM robots order by modified desc", 1 ); print_r($robot); public *boolean* **insert** (*string* | *array* $table, *array* $values, [*array* $fields], [*array* $dataTypes]) Inserts data into a table using custom RDBMS SQL syntax .. code-block:: php insert( "robots", ["Astro Boy", 1952], ["name", "year"] ); // Next SQL sentence is sent to the database system INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952); public *boolean* **insertAsDict** (*string* $table, *array* $data, [*array* $dataTypes]) Inserts data into a table using custom RBDM SQL syntax .. code-block:: php insertAsDict( "robots", [ "name" => "Astro Boy", "year" => 1952, ] ); // Next SQL sentence is sent to the database system INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952); public *boolean* **update** (*string* | *array* $table, *array* $fields, *array* $values, [*string* | *array* $whereCondition], [*array* $dataTypes]) Updates data on a table using custom RBDM SQL syntax .. code-block:: php update( "robots", ["name"], ["New Astro Boy"], "id = 101" ); // Next SQL sentence is sent to the database system UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101 // Updating existing robot with array condition and $dataTypes $success = $connection->update( "robots", ["name"], ["New Astro Boy"], [ "conditions" => "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 not escaped. public *boolean* **updateAsDict** (*string* $table, *array* $data, [*string* $whereCondition], [*array* $dataTypes]) Updates data on a table using custom RBDM SQL syntax Another, more convenient syntax .. code-block:: php updateAsDict( "robots", [ "name" => "New Astro Boy", ], "id = 101" ); // Next SQL sentence is sent to the database system UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101 public *boolean* **delete** (*string* | *array* $table, [*string* $whereCondition], [*array* $placeholders], [*array* $dataTypes]) Deletes data from a table using custom RBDM SQL syntax .. code-block:: php delete( "robots", "id = 101" ); // Next SQL sentence is generated DELETE FROM `robots` WHERE `id` = 101 public **escapeIdentifier** (*array* | *string* $identifier) Escapes a column/table/schema name .. code-block:: php escapeIdentifier( "robots" ); $escapedTable = $connection->escapeIdentifier( [ "store", "robots", ] ); public *string* **getColumnList** (*array* $columnList) Gets a list of columns public **limit** (*mixed* $sqlQuery, *mixed* $number) Appends a LIMIT clause to $sqlQuery argument .. code-block:: php limit("SELECT * FROM robots", 5); public **tableExists** (*mixed* $tableName, [*mixed* $schemaName]) Generates SQL checking for the existence of a schema.table .. code-block:: php tableExists("blog", "posts") ); public **viewExists** (*mixed* $viewName, [*mixed* $schemaName]) Generates SQL checking for the existence of a schema.view .. code-block:: php viewExists("active_users", "posts") ); public **forUpdate** (*mixed* $sqlQuery) Returns a SQL modified with a FOR UPDATE clause public **sharedLock** (*mixed* $sqlQuery) Returns a SQL modified with a LOCK IN SHARE MODE clause public **createTable** (*mixed* $tableName, *mixed* $schemaName, *array* $definition) Creates a table public **dropTable** (*mixed* $tableName, [*mixed* $schemaName], [*mixed* $ifExists]) Drops a table from a schema/database public **createView** (*mixed* $viewName, *array* $definition, [*mixed* $schemaName]) Creates a view public **dropView** (*mixed* $viewName, [*mixed* $schemaName], [*mixed* $ifExists]) Drops a view public **addColumn** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ColumnInterface ` $column) Adds a column to a table public **modifyColumn** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ColumnInterface ` $column, [:doc:`Phalcon\\Db\\ColumnInterface ` $currentColumn]) Modifies a table column based on a definition public **dropColumn** (*mixed* $tableName, *mixed* $schemaName, *mixed* $columnName) Drops a column from a table public **addIndex** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\IndexInterface ` $index) Adds an index to a table public **dropIndex** (*mixed* $tableName, *mixed* $schemaName, *mixed* $indexName) Drop an index from a table public **addPrimaryKey** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\IndexInterface ` $index) Adds a primary key to a table public **dropPrimaryKey** (*mixed* $tableName, *mixed* $schemaName) Drops a table's primary key public **addForeignKey** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ReferenceInterface ` $reference) Adds a foreign key to a table public **dropForeignKey** (*mixed* $tableName, *mixed* $schemaName, *mixed* $referenceName) Drops a foreign key from a table public **getColumnDefinition** (:doc:`Phalcon\\Db\\ColumnInterface ` $column) Returns the SQL column definition from a column public **listTables** ([*mixed* $schemaName]) List all tables on a database .. code-block:: php listTables("blog") ); public **listViews** ([*mixed* $schemaName]) List all views on a database .. code-block:: php listViews("blog") ); public :doc:`Phalcon\\Db\\Index `\ [] **describeIndexes** (*string* $table, [*string* $schema]) Lists table indexes .. code-block:: php describeIndexes("robots_parts") ); public **describeReferences** (*mixed* $table, [*mixed* $schema]) Lists table references .. code-block:: php describeReferences("robots_parts") ); public **tableOptions** (*mixed* $tableName, [*mixed* $schemaName]) Gets creation options from a table .. code-block:: php tableOptions("robots") ); public **createSavepoint** (*mixed* $name) Creates a new savepoint public **releaseSavepoint** (*mixed* $name) Releases given savepoint public **rollbackSavepoint** (*mixed* $name) Rollbacks given savepoint public **setNestedTransactionsWithSavepoints** (*mixed* $nestedTransactionsWithSavepoints) Set if nested transactions should use savepoints public **isNestedTransactionsWithSavepoints** () Returns if nested transactions should use savepoints public **getNestedTransactionSavepointName** () Returns the savepoint name to use for nested transactions public **getDefaultIdValue** () Returns the default identity value to be inserted in an identity column .. code-block:: php insert( "robots", [ $connection->getDefaultIdValue(), "Astro Boy", 1952, ], [ "id", "name", "year", ] ); public **getDefaultValue** () Returns the default value to make the RBDM use the default value declared in the table definition .. code-block:: php insert( "robots", [ "Astro Boy", $connection->getDefaultValue() ], [ "name", "year", ] ); public **supportSequences** () Check whether the database system requires a sequence to produce auto-numeric values public **useExplicitIdValue** () Check whether the database system requires an explicit value for identity columns public **getDescriptor** () Return descriptor used to connect to the active database public *string* **getConnectionId** () Gets the active connection unique identifier public **getSQLStatement** () Active SQL statement in the object public **getRealSQLStatement** () Active SQL statement in the object without replace bound parameters public *array* **getSQLBindTypes** () Active SQL statement in the object abstract public **connect** ([*array* $descriptor]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **query** (*mixed* $sqlStatement, [*mixed* $placeholders], [*mixed* $dataTypes]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **execute** (*mixed* $sqlStatement, [*mixed* $placeholders], [*mixed* $dataTypes]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **affectedRows** () inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **close** () inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **escapeString** (*mixed* $str) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **lastInsertId** ([*mixed* $sequenceName]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **begin** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **rollback** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **commit** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **isUnderTransaction** () inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **getInternalHandler** () inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ... abstract public **describeColumns** (*mixed* $table, [*mixed* $schema]) inherited from :doc:`Phalcon\\Db\\AdapterInterface ` ...