Class **Phalcon\\Db\\Adapter\\Pdo\\Mysql** ========================================== *extends* abstract class :doc:`Phalcon\\Db\\Adapter\\Pdo ` *implements* :doc:`Phalcon\\Events\\EventsAwareInterface `, :doc:`Phalcon\\Db\\AdapterInterface ` .. role:: raw-html(raw) :format: html :raw-html:`Source on GitHub` Specific functions for the Mysql database system .. code-block:: php 'localhost', 'dbname' => 'blog', 'port' => 3306, 'username' => 'sigma', 'password' => 'secret' ]; $connection = new Mysql($config); Methods ------- public **escapeIdentifier** (*mixed* $identifier) Escapes a column/table/schema name .. code-block:: php escapeIdentifier('my_table'); // `my_table` echo $connection->escapeIdentifier(['companies', 'name']); // `companies`.`name` .. code-block:: php describeColumns("posts")); public :doc:`Phalcon\\Db\\IndexInterface `\ [] **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 **__construct** (*array* $descriptor) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Constructor for Phalcon\\Db\\Adapter\\Pdo public **connect** ([*array* $descriptor]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` This method is automatically called in \\Phalcon\\Db\\Adapter\\Pdo constructor. Call it when you need to restore a database connection. .. code-block:: php 'localhost', 'username' => 'sigma', 'password' => 'secret', 'dbname' => 'blog', 'port' => 3306, ]); // Reconnect $connection->connect(); public **prepare** (*mixed* $sqlStatement) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Returns a PDO prepared statement to be executed with 'executePrepared' .. code-block:: php prepare('SELECT * FROM robots WHERE name = :name'); $result = $connection->executePrepared($statement, ['name' => 'Voltron'], ['name' => Column::BIND_PARAM_INT]); public `PDOStatement `_ **executePrepared** (`PDOStatement `_ $statement, *array* $placeholders, *array* $dataTypes) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Executes a prepared statement binding. This function uses integer indexes starting from zero .. code-block:: php prepare('SELECT * FROM robots WHERE name = :name'); $result = $connection->executePrepared($statement, ['name' => 'Voltron'], ['name' => Column::BIND_PARAM_INT]); public **query** (*mixed* $sqlStatement, [*mixed* $bindParams], [*mixed* $bindTypes]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` 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 .. code-block:: php query("SELECT * FROM robots WHERE type='mechanical'"); $resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical")); public **execute** (*mixed* $sqlStatement, [*mixed* $bindParams], [*mixed* $bindTypes]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server doesn't return any rows .. code-block:: php execute("INSERT INTO robots VALUES (1, 'Astro Boy')"); $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Astro Boy')); public **affectedRows** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Returns the number of affected rows by the lastest INSERT/UPDATE/DELETE executed in the database system .. code-block:: php execute("DELETE FROM robots"); echo $connection->affectedRows(), ' were deleted'; public **close** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Closes the active connection returning success. Phalcon automatically closes and destroys active connections when the request ends public **escapeString** (*mixed* $str) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Escapes a value to avoid SQL injections according to the active charset in the connection .. code-block:: php escapeString('some dangerous value'); public **convertBoundParams** (*mixed* $sql, [*array* $params]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Converts bound parameters such as :name: or ?1 into PDO bind params ? .. code-block:: php convertBoundParams('SELECT * FROM robots WHERE name = :name:', array('Bender'))); public *int* | *boolean* **lastInsertId** ([*string* $sequenceName]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Returns the insert id for the auto_increment/serial column inserted in the lastest executed SQL statement .. code-block:: php insert( "robots", array("Astro Boy", 1952), array("name", "year") ); //Getting the generated id $id = $connection->lastInsertId(); public **begin** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Starts a transaction in the connection public **rollback** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Rollbacks the active transaction in the connection public **commit** ([*mixed* $nesting]) inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Commits the active transaction in the connection public **getTransactionLevel** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Returns the current transaction nesting level public **isUnderTransaction** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Checks whether the connection is under a transaction .. code-block:: php begin(); var_dump($connection->isUnderTransaction()); //true public **getInternalHandler** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Return internal PDO handler public *array* **getErrorInfo** () inherited from :doc:`Phalcon\\Db\\Adapter\\Pdo ` Return the error info, if any public **getDialectType** () inherited from :doc:`Phalcon\\Db\\Adapter ` Name of the dialect used public **getType** () inherited from :doc:`Phalcon\\Db\\Adapter ` Type of database system the adapter is used for public **getSqlVariables** () inherited from :doc:`Phalcon\\Db\\Adapter ` Active SQL bound parameter variables public **setEventsManager** (:doc:`Phalcon\\Events\\ManagerInterface ` $eventsManager) inherited from :doc:`Phalcon\\Db\\Adapter ` Sets the event manager public **getEventsManager** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns the internal event manager public **setDialect** (:doc:`Phalcon\\Db\\DialectInterface ` $dialect) inherited from :doc:`Phalcon\\Db\\Adapter ` Sets the dialect used to produce the SQL public **getDialect** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns internal dialect instance public **fetchOne** (*mixed* $sqlQuery, [*mixed* $fetchMode], [*mixed* $bindParams], [*mixed* $bindTypes]) inherited from :doc:`Phalcon\\Db\\Adapter ` 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]) inherited from :doc:`Phalcon\\Db\\Adapter ` 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, array('name' => '%robot%') ); foreach($robots as $robot){ print_r($robot); } public *string* | ** **fetchColumn** (*string* $sqlQuery, [*array* $placeholders], [*int* | *string* $column]) inherited from :doc:`Phalcon\\Db\\Adapter ` 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]) inherited from :doc:`Phalcon\\Db\\Adapter ` Inserts data into a table using custom RDBMS SQL syntax .. code-block:: php insert( "robots", array("Astro Boy", 1952), array("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]) inherited from :doc:`Phalcon\\Db\\Adapter ` Inserts data into a table using custom RBDM SQL syntax .. code-block:: php insertAsDict( "robots", array( "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]) inherited from :doc:`Phalcon\\Db\\Adapter ` Updates data on a table using custom RBDM SQL syntax .. code-block:: php update( "robots", array("name"), array("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", array("name"), array("New Astro Boy"), array( 'conditions' => "id = ?", 'bind' => array($some_unsafe_id), 'bindTypes' => array(PDO::PARAM_INT) //use only if you use $dataTypes param ), array(PDO::PARAM_STR) ); Warning! If $whereCondition is string it not escaped. public *boolean* **updateAsDict** (*string* $table, *array* $data, [*string* $whereCondition], [*array* $dataTypes]) inherited from :doc:`Phalcon\\Db\\Adapter ` Updates data on a table using custom RBDM SQL syntax Another, more convenient syntax .. code-block:: php updateAsDict( "robots", array( "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]) inherited from :doc:`Phalcon\\Db\\Adapter ` 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 *string* **getColumnList** (*array* $columnList) inherited from :doc:`Phalcon\\Db\\Adapter ` Gets a list of columns public **limit** (*mixed* $sqlQuery, *mixed* $number) inherited from :doc:`Phalcon\\Db\\Adapter ` Appends a LIMIT clause to $sqlQuery argument .. code-block:: php limit("SELECT * FROM robots", 5); public **tableExists** (*mixed* $tableName, [*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` Generates SQL checking for the existence of a schema.table .. code-block:: php tableExists("blog", "posts")); public **viewExists** (*mixed* $viewName, [*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` Generates SQL checking for the existence of a schema.view .. code-block:: php viewExists("active_users", "posts")); public **forUpdate** (*mixed* $sqlQuery) inherited from :doc:`Phalcon\\Db\\Adapter ` Returns a SQL modified with a FOR UPDATE clause public **sharedLock** (*mixed* $sqlQuery) inherited from :doc:`Phalcon\\Db\\Adapter ` Returns a SQL modified with a LOCK IN SHARE MODE clause public **createTable** (*mixed* $tableName, *mixed* $schemaName, *array* $definition) inherited from :doc:`Phalcon\\Db\\Adapter ` Creates a table public **dropTable** (*mixed* $tableName, [*mixed* $schemaName], [*mixed* $ifExists]) inherited from :doc:`Phalcon\\Db\\Adapter ` Drops a table from a schema/database public **createView** (*mixed* $viewName, *array* $definition, [*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` Creates a view public **dropView** (*mixed* $viewName, [*mixed* $schemaName], [*mixed* $ifExists]) inherited from :doc:`Phalcon\\Db\\Adapter ` Drops a view public **addColumn** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ColumnInterface ` $column) inherited from :doc:`Phalcon\\Db\\Adapter ` Adds a column to a table public **modifyColumn** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ColumnInterface ` $column, [:doc:`Phalcon\\Db\\ColumnInterface ` $currentColumn]) inherited from :doc:`Phalcon\\Db\\Adapter ` Modifies a table column based on a definition public **dropColumn** (*mixed* $tableName, *mixed* $schemaName, *mixed* $columnName) inherited from :doc:`Phalcon\\Db\\Adapter ` Drops a column from a table public **addIndex** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\IndexInterface ` $index) inherited from :doc:`Phalcon\\Db\\Adapter ` Adds an index to a table public **dropIndex** (*mixed* $tableName, *mixed* $schemaName, *mixed* $indexName) inherited from :doc:`Phalcon\\Db\\Adapter ` Drop an index from a table public **addPrimaryKey** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\IndexInterface ` $index) inherited from :doc:`Phalcon\\Db\\Adapter ` Adds a primary key to a table public **dropPrimaryKey** (*mixed* $tableName, *mixed* $schemaName) inherited from :doc:`Phalcon\\Db\\Adapter ` Drops a table's primary key public **addForeignKey** (*mixed* $tableName, *mixed* $schemaName, :doc:`Phalcon\\Db\\ReferenceInterface ` $reference) inherited from :doc:`Phalcon\\Db\\Adapter ` Adds a foreign key to a table public **dropForeignKey** (*mixed* $tableName, *mixed* $schemaName, *mixed* $referenceName) inherited from :doc:`Phalcon\\Db\\Adapter ` Drops a foreign key from a table public **getColumnDefinition** (:doc:`Phalcon\\Db\\ColumnInterface ` $column) inherited from :doc:`Phalcon\\Db\\Adapter ` Returns the SQL column definition from a column public **listTables** ([*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` List all tables on a database .. code-block:: php listTables("blog")); public **listViews** ([*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` List all views on a database .. code-block:: php listViews("blog")); public **tableOptions** (*mixed* $tableName, [*mixed* $schemaName]) inherited from :doc:`Phalcon\\Db\\Adapter ` Gets creation options from a table .. code-block:: php tableOptions('robots')); public **createSavepoint** (*mixed* $name) inherited from :doc:`Phalcon\\Db\\Adapter ` Creates a new savepoint public **releaseSavepoint** (*mixed* $name) inherited from :doc:`Phalcon\\Db\\Adapter ` Releases given savepoint public **rollbackSavepoint** (*mixed* $name) inherited from :doc:`Phalcon\\Db\\Adapter ` Rollbacks given savepoint public **setNestedTransactionsWithSavepoints** (*mixed* $nestedTransactionsWithSavepoints) inherited from :doc:`Phalcon\\Db\\Adapter ` Set if nested transactions should use savepoints public **isNestedTransactionsWithSavepoints** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns if nested transactions should use savepoints public **getNestedTransactionSavepointName** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns the savepoint name to use for nested transactions public **getDefaultIdValue** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns the default identity value to be inserted in an identity column .. code-block:: php insert( "robots", array($connection->getDefaultIdValue(), "Astro Boy", 1952), array("id", "name", "year") ); public **getDefaultValue** () inherited from :doc:`Phalcon\\Db\\Adapter ` Returns the default value to make the RBDM use the default value declared in the table definition .. code-block:: php insert( "robots", array("Astro Boy", $connection->getDefaultValue()), array("name", "year") ); public **supportSequences** () inherited from :doc:`Phalcon\\Db\\Adapter ` Check whether the database system requires a sequence to produce auto-numeric values public **useExplicitIdValue** () inherited from :doc:`Phalcon\\Db\\Adapter ` Check whether the database system requires an explicit value for identity columns public **getDescriptor** () inherited from :doc:`Phalcon\\Db\\Adapter ` Return descriptor used to connect to the active database public *string* **getConnectionId** () inherited from :doc:`Phalcon\\Db\\Adapter ` Gets the active connection unique identifier public **getSQLStatement** () inherited from :doc:`Phalcon\\Db\\Adapter ` Active SQL statement in the object public **getRealSQLStatement** () inherited from :doc:`Phalcon\\Db\\Adapter ` Active SQL statement in the object without replace bound paramters public *array* **getSQLBindTypes** () inherited from :doc:`Phalcon\\Db\\Adapter ` Active SQL statement in the object