implements Phalcon\Events\EventsAwareInterface, Phalcon\Db\AdapterInterface
Base class for Phalcon\Db adapters
Phalcon\Db\Adapter constructor
Sets the event manager
Returns the internal event manager
Sets the dialect used to produce the SQL
Returns internal dialect instance
Returns the first row in a SQL query result
//Getting first robot $robot = $connection->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);
Dumps the complete result of a query into an array
//Getting all robots with associative indexes only $robots = $connection->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); }
Inserts data into a table using custom RBDM SQL syntax
//Inserting a new robot $success = $connection->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);
Updates data on a table using custom RBDM SQL syntax
//Updating existing robot $success = $connection->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
Deletes data from a table using custom RBDM SQL syntax
//Deleting existing robot $success = $connection->delete( "robots", "id = 101" ); //Next SQL sentence is generated DELETE FROM `robots` WHERE `id` = 101
Gets a list of columns
Appends a LIMIT clause to $sqlQuery argument
echo $connection->limit("SELECT * FROM robots", 5);
Generates SQL checking for the existence of a schema.table
var_dump($connection->tableExists("blog", "posts"));
Generates SQL checking for the existence of a schema.view
var_dump($connection->viewExists("active_users", "posts"));
Returns a SQL modified with a FOR UPDATE clause
Returns a SQL modified with a LOCK IN SHARE MODE clause
Creates a table
Drops a table from a schema/database
Creates a view
Drops a view
Adds a column to a table
Modifies a table column based on a definition
Drops a column from a table
Adds an index to a table
Drop an index from a table
Adds a primary key to a table
Drops a table’s primary key
Adds a foreign key to a table
Drops a foreign key from a table
Returns the SQL column definition from a column
List all tables on a database
print_r($connection->listTables("blog"));
List all views on a database
<?php print_r($connection->listViews("blog")); ?>
Lists table indexes
print_r($connection->describeIndexes('robots_parts'));
Lists table references
print_r($connection->describeReferences('robots_parts'));
Gets creation options from a table
print_r($connection->tableOptions('robots'));
Creates a new savepoint
Releases given savepoint
Rollbacks given savepoint
Set if nested transactions should use savepoints
Returns if nested transactions should use savepoints
Returns the savepoint name to use for nested transactions
Returns the default identity value to be inserted in an identity column
//Inserting a new robot with a valid default value for the column 'id' $success = $connection->insert( "robots", array($connection->getDefaultIdValue(), "Astro Boy", 1952), array("id", "name", "year") );
Check whether the database system requires a sequence to produce auto-numeric values
Check whether the database system requires an explicit value for identity columns
Return descriptor used to connect to the active database
Gets the active connection unique identifier
Active SQL statement in the object
Active SQL statement in the object without replace bound paramters
Active SQL statement in the object
Active SQL statement in the object
Returns type of database system the adapter is used for
Returns the name of the dialect used
This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. Call it when you need to restore a database connection
Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server return rows
Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server don’t return any row
Returns the number of affected rows by the last INSERT/UPDATE/DELETE reported by the database system
Closes active connection returning success. Phalcon automatically closes and destroys active connections within Phalcon\Db\Pool
Escapes a column/table/schema name
Escapes a value to avoid SQL injections
Converts bound params like :name: or ?1 into ? bind params
Returns insert id for the auto_increment column inserted in the last SQL statement
Starts a transaction in the connection
Rollbacks the active transaction in the connection
Commits the active transaction in the connection
Checks whether connection is under database transaction
Return internal PDO handler
Returns an array of Phalcon\Db\Column objects describing a table
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Db_Adapter.html