Class Phalcon\Db\Adapter\Pdo\Sqlite

extends abstract class Phalcon\Db\Adapter\Pdo

implements Phalcon\Db\AdapterInterface, Phalcon\Events\EventsAwareInterface

Source on GitHub

Specific functions for the Sqlite database system

  1. <?php
  2. use Phalcon\Db\Adapter\Pdo\Sqlite;
  3. $connection = new Sqlite(
  4. [
  5. "dbname" => "/tmp/test.sqlite",
  6. ]
  7. );

Methods

public connect ([array $descriptor])

This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. Call it when you need to restore a database connection.

public describeColumns (mixed $table, [mixed $schema])

Returns an array of Phalcon\Db\Column objects describing a table

  1. <?php
  2. print_r(
  3. $connection->describeColumns("posts")
  4. );

public Phalcon\Db\IndexInterface[] describeIndexes (string $table, [string $schema])

Lists table indexes

  1. <?php
  2. print_r(
  3. $connection->describeIndexes("robots_parts")
  4. );

public Phalcon\Db\ReferenceInterface[] describeReferences (string $table, [string $schema])

Lists table references

public useExplicitIdValue ()

Check whether the database system requires an explicit value for identity columns

public getDefaultValue ()

Returns the default value to make the RBDM use the default value declared in the table definition

  1. <?php
  2. // Inserting a new robot with a valid default value for the column 'year'
  3. $success = $connection->insert(
  4. "robots",
  5. [
  6. "Astro Boy",
  7. $connection->getDefaultValue(),
  8. ],
  9. [
  10. "name",
  11. "year",
  12. ]
  13. );

public __construct (array $descriptor) inherited from Phalcon\Db\Adapter\Pdo

Constructor for Phalcon\Db\Adapter\Pdo

public prepare (mixed $sqlStatement) inherited from Phalcon\Db\Adapter\Pdo

Returns a PDO prepared statement to be executed with ‘executePrepared’

  1. <?php
  2. use Phalcon\Db\Column;
  3. $statement = $db->prepare(
  4. "SELECT * FROM robots WHERE name = :name"
  5. );
  6. $result = $connection->executePrepared(
  7. $statement,
  8. [
  9. "name" => "Voltron",
  10. ],
  11. [
  12. "name" => Column::BIND_PARAM_INT,
  13. ]
  14. );

public PDOStatement executePrepared (PDOStatement $statement, array $placeholders, array $dataTypes) inherited from Phalcon\Db\Adapter\Pdo

Executes a prepared statement binding. This function uses integer indexes starting from zero

  1. <?php
  2. use Phalcon\Db\Column;
  3. $statement = $db->prepare(
  4. "SELECT * FROM robots WHERE name = :name"
  5. );
  6. $result = $connection->executePrepared(
  7. $statement,
  8. [
  9. "name" => "Voltron",
  10. ],
  11. [
  12. "name" => Column::BIND_PARAM_INT,
  13. ]
  14. );

public query (mixed $sqlStatement, [mixed $bindParams], [mixed $bindTypes]) inherited from 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

  1. <?php
  2. // Querying data
  3. $resultset = $connection->query(
  4. "SELECT * FROM robots WHERE type = 'mechanical'"
  5. );
  6. $resultset = $connection->query(
  7. "SELECT * FROM robots WHERE type = ?",
  8. [
  9. "mechanical",
  10. ]
  11. );

public execute (mixed $sqlStatement, [mixed $bindParams], [mixed $bindTypes]) inherited from 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

  1. <?php
  2. // Inserting data
  3. $success = $connection->execute(
  4. "INSERT INTO robots VALUES (1, 'Astro Boy')"
  5. );
  6. $success = $connection->execute(
  7. "INSERT INTO robots VALUES (?, ?)",
  8. [
  9. 1,
  10. "Astro Boy",
  11. ]
  12. );

public affectedRows () inherited from Phalcon\Db\Adapter\Pdo

Returns the number of affected rows by the latest INSERT/UPDATE/DELETE executed in the database system

  1. <?php
  2. $connection->execute(
  3. "DELETE FROM robots"
  4. );
  5. echo $connection->affectedRows(), " were deleted";

public close () inherited from 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 Phalcon\Db\Adapter\Pdo

Escapes a value to avoid SQL injections according to the active charset in the connection

  1. <?php
  2. $escapedStr = $connection->escapeString("some dangerous value");

public convertBoundParams (mixed $sql, [array $params]) inherited from Phalcon\Db\Adapter\Pdo

Converts bound parameters such as :name: or ?1 into PDO bind params ?

  1. <?php
  2. print_r(
  3. $connection->convertBoundParams(
  4. "SELECT * FROM robots WHERE name = :name:",
  5. [
  6. "Bender",
  7. ]
  8. )
  9. );

public int | boolean lastInsertId ([string $sequenceName]) inherited from Phalcon\Db\Adapter\Pdo

Returns the insert id for the auto_increment/serial column inserted in the latest executed SQL statement

  1. <?php
  2. // Inserting a new robot
  3. $success = $connection->insert(
  4. "robots",
  5. [
  6. "Astro Boy",
  7. 1952,
  8. ],
  9. [
  10. "name",
  11. "year",
  12. ]
  13. );
  14. // Getting the generated id
  15. $id = $connection->lastInsertId();

public begin ([mixed $nesting]) inherited from Phalcon\Db\Adapter\Pdo

Starts a transaction in the connection

public rollback ([mixed $nesting]) inherited from Phalcon\Db\Adapter\Pdo

Rollbacks the active transaction in the connection

public commit ([mixed $nesting]) inherited from Phalcon\Db\Adapter\Pdo

Commits the active transaction in the connection

public getTransactionLevel () inherited from Phalcon\Db\Adapter\Pdo

Returns the current transaction nesting level

public isUnderTransaction () inherited from Phalcon\Db\Adapter\Pdo

Checks whether the connection is under a transaction

  1. <?php
  2. $connection->begin();
  3. // true
  4. var_dump(
  5. $connection->isUnderTransaction()
  6. );

public getInternalHandler () inherited from Phalcon\Db\Adapter\Pdo

Return internal PDO handler

public array getErrorInfo () inherited from Phalcon\Db\Adapter\Pdo

Return the error info, if any

public getDialectType () inherited from Phalcon\Db\Adapter

Name of the dialect used

public getType () inherited from Phalcon\Db\Adapter

Type of database system the adapter is used for

public getSqlVariables () inherited from Phalcon\Db\Adapter

Active SQL bound parameter variables

public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager) inherited from Phalcon\Db\Adapter

Sets the event manager

public getEventsManager () inherited from Phalcon\Db\Adapter

Returns the internal event manager

public setDialect (Phalcon\Db\DialectInterface $dialect) inherited from Phalcon\Db\Adapter

Sets the dialect used to produce the SQL

public getDialect () inherited from Phalcon\Db\Adapter

Returns internal dialect instance

public fetchOne (mixed $sqlQuery, [mixed $fetchMode], [mixed $bindParams], [mixed $bindTypes]) inherited from Phalcon\Db\Adapter

Returns the first row in a SQL query result

  1. <?php
  2. // Getting first robot
  3. $robot = $connection->fetchOne("SELECT * FROM robots");
  4. print_r($robot);
  5. // Getting first robot with associative indexes only
  6. $robot = $connection->fetchOne("SELECT * FROM robots", \Phalcon\Db::FETCH_ASSOC);
  7. print_r($robot);

public array fetchAll (string $sqlQuery, [int $fetchMode], [array $bindParams], [array $bindTypes]) inherited from Phalcon\Db\Adapter

Dumps the complete result of a query into an array

  1. <?php
  2. // Getting all robots with associative indexes only
  3. $robots = $connection->fetchAll(
  4. "SELECT * FROM robots",
  5. \Phalcon\Db::FETCH_ASSOC
  6. );
  7. foreach ($robots as $robot) {
  8. print_r($robot);
  9. }
  10. // Getting all robots that contains word "robot" withing the name
  11. $robots = $connection->fetchAll(
  12. "SELECT * FROM robots WHERE name LIKE :name",
  13. \Phalcon\Db::FETCH_ASSOC,
  14. [
  15. "name" => "%robot%",
  16. ]
  17. );
  18. foreach($robots as $robot) {
  19. print_r($robot);
  20. }

public string | ** fetchColumn (string $sqlQuery, [array $placeholders], [int | string $column]) inherited from Phalcon\Db\Adapter

Returns the n’th field of first row in a SQL query result

  1. <?php
  2. // Getting count of robots
  3. $robotsCount = $connection->fetchColumn("SELECT count(*) FROM robots");
  4. print_r($robotsCount);
  5. // Getting name of last edited robot
  6. $robot = $connection->fetchColumn(
  7. "SELECT id, name FROM robots order by modified desc",
  8. 1
  9. );
  10. print_r($robot);

public boolean insert (string | array $table, array $values, [array $fields], [array $dataTypes]) inherited from Phalcon\Db\Adapter

Inserts data into a table using custom RDBMS SQL syntax

  1. <?php
  2. // Inserting a new robot
  3. $success = $connection->insert(
  4. "robots",
  5. ["Astro Boy", 1952],
  6. ["name", "year"]
  7. );
  8. // Next SQL sentence is sent to the database system
  9. INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952);

public boolean insertAsDict (string $table, array $data, [array $dataTypes]) inherited from Phalcon\Db\Adapter

Inserts data into a table using custom RBDM SQL syntax

  1. <?php
  2. // Inserting a new robot
  3. $success = $connection->insertAsDict(
  4. "robots",
  5. [
  6. "name" => "Astro Boy",
  7. "year" => 1952,
  8. ]
  9. );
  10. // Next SQL sentence is sent to the database system
  11. 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 Phalcon\Db\Adapter

Updates data on a table using custom RBDM SQL syntax

  1. <?php
  2. // Updating existing robot
  3. $success = $connection->update(
  4. "robots",
  5. ["name"],
  6. ["New Astro Boy"],
  7. "id = 101"
  8. );
  9. // Next SQL sentence is sent to the database system
  10. UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101
  11. // Updating existing robot with array condition and $dataTypes
  12. $success = $connection->update(
  13. "robots",
  14. ["name"],
  15. ["New Astro Boy"],
  16. [
  17. "conditions" => "id = ?",
  18. "bind" => [$some_unsafe_id],
  19. "bindTypes" => [PDO::PARAM_INT], // use only if you use $dataTypes param
  20. ],
  21. [
  22. PDO::PARAM_STR
  23. ]
  24. );

Warning! If $whereCondition is string it not escaped.

public boolean updateAsDict (string $table, array $data, [string $whereCondition], [array $dataTypes]) inherited from Phalcon\Db\Adapter

Updates data on a table using custom RBDM SQL syntax Another, more convenient syntax

  1. <?php
  2. // Updating existing robot
  3. $success = $connection->updateAsDict(
  4. "robots",
  5. [
  6. "name" => "New Astro Boy",
  7. ],
  8. "id = 101"
  9. );
  10. // Next SQL sentence is sent to the database system
  11. UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

public boolean delete (string | array $table, [string $whereCondition], [array $placeholders], [array $dataTypes]) inherited from Phalcon\Db\Adapter

Deletes data from a table using custom RBDM SQL syntax

  1. <?php
  2. // Deleting existing robot
  3. $success = $connection->delete(
  4. "robots",
  5. "id = 101"
  6. );
  7. // Next SQL sentence is generated
  8. DELETE FROM `robots` WHERE `id` = 101

public escapeIdentifier (array | string $identifier) inherited from Phalcon\Db\Adapter

Escapes a column/table/schema name

  1. <?php
  2. $escapedTable = $connection->escapeIdentifier(
  3. "robots"
  4. );
  5. $escapedTable = $connection->escapeIdentifier(
  6. [
  7. "store",
  8. "robots",
  9. ]
  10. );

public string getColumnList (array $columnList) inherited from Phalcon\Db\Adapter

Gets a list of columns

public limit (mixed $sqlQuery, mixed $number) inherited from Phalcon\Db\Adapter

Appends a LIMIT clause to $sqlQuery argument

  1. <?php
  2. echo $connection->limit("SELECT * FROM robots", 5);

public tableExists (mixed $tableName, [mixed $schemaName]) inherited from Phalcon\Db\Adapter

Generates SQL checking for the existence of a schema.table

  1. <?php
  2. var_dump(
  3. $connection->tableExists("blog", "posts")
  4. );

public viewExists (mixed $viewName, [mixed $schemaName]) inherited from Phalcon\Db\Adapter

Generates SQL checking for the existence of a schema.view

  1. <?php
  2. var_dump(
  3. $connection->viewExists("active_users", "posts")
  4. );

public forUpdate (mixed $sqlQuery) inherited from Phalcon\Db\Adapter

Returns a SQL modified with a FOR UPDATE clause

public sharedLock (mixed $sqlQuery) inherited from Phalcon\Db\Adapter

Returns a SQL modified with a LOCK IN SHARE MODE clause

public createTable (mixed $tableName, mixed $schemaName, array $definition) inherited from Phalcon\Db\Adapter

Creates a table

public dropTable (mixed $tableName, [mixed $schemaName], [mixed $ifExists]) inherited from Phalcon\Db\Adapter

Drops a table from a schema/database

public createView (mixed $viewName, array $definition, [mixed $schemaName]) inherited from Phalcon\Db\Adapter

Creates a view

public dropView (mixed $viewName, [mixed $schemaName], [mixed $ifExists]) inherited from Phalcon\Db\Adapter

Drops a view

public addColumn (mixed $tableName, mixed $schemaName, Phalcon\Db\ColumnInterface $column) inherited from Phalcon\Db\Adapter

Adds a column to a table

public modifyColumn (mixed $tableName, mixed $schemaName, Phalcon\Db\ColumnInterface $column, [Phalcon\Db\ColumnInterface $currentColumn]) inherited from Phalcon\Db\Adapter

Modifies a table column based on a definition

public dropColumn (mixed $tableName, mixed $schemaName, mixed $columnName) inherited from Phalcon\Db\Adapter

Drops a column from a table

public addIndex (mixed $tableName, mixed $schemaName, Phalcon\Db\IndexInterface $index) inherited from Phalcon\Db\Adapter

Adds an index to a table

public dropIndex (mixed $tableName, mixed $schemaName, mixed $indexName) inherited from Phalcon\Db\Adapter

Drop an index from a table

public addPrimaryKey (mixed $tableName, mixed $schemaName, Phalcon\Db\IndexInterface $index) inherited from Phalcon\Db\Adapter

Adds a primary key to a table

public dropPrimaryKey (mixed $tableName, mixed $schemaName) inherited from Phalcon\Db\Adapter

Drops a table’s primary key

public addForeignKey (mixed $tableName, mixed $schemaName, Phalcon\Db\ReferenceInterface $reference) inherited from Phalcon\Db\Adapter

Adds a foreign key to a table

public dropForeignKey (mixed $tableName, mixed $schemaName, mixed $referenceName) inherited from Phalcon\Db\Adapter

Drops a foreign key from a table

public getColumnDefinition (Phalcon\Db\ColumnInterface $column) inherited from Phalcon\Db\Adapter

Returns the SQL column definition from a column

public listTables ([mixed $schemaName]) inherited from Phalcon\Db\Adapter

List all tables on a database

  1. <?php
  2. print_r(
  3. $connection->listTables("blog")
  4. );

public listViews ([mixed $schemaName]) inherited from Phalcon\Db\Adapter

List all views on a database

  1. <?php
  2. print_r(
  3. $connection->listViews("blog")
  4. );

public tableOptions (mixed $tableName, [mixed $schemaName]) inherited from Phalcon\Db\Adapter

Gets creation options from a table

  1. <?php
  2. print_r(
  3. $connection->tableOptions("robots")
  4. );

public createSavepoint (mixed $name) inherited from Phalcon\Db\Adapter

Creates a new savepoint

public releaseSavepoint (mixed $name) inherited from Phalcon\Db\Adapter

Releases given savepoint

public rollbackSavepoint (mixed $name) inherited from Phalcon\Db\Adapter

Rollbacks given savepoint

public setNestedTransactionsWithSavepoints (mixed $nestedTransactionsWithSavepoints) inherited from Phalcon\Db\Adapter

Set if nested transactions should use savepoints

public isNestedTransactionsWithSavepoints () inherited from Phalcon\Db\Adapter

Returns if nested transactions should use savepoints

public getNestedTransactionSavepointName () inherited from Phalcon\Db\Adapter

Returns the savepoint name to use for nested transactions

public getDefaultIdValue () inherited from Phalcon\Db\Adapter

Returns the default identity value to be inserted in an identity column

  1. <?php
  2. // Inserting a new robot with a valid default value for the column 'id'
  3. $success = $connection->insert(
  4. "robots",
  5. [
  6. $connection->getDefaultIdValue(),
  7. "Astro Boy",
  8. 1952,
  9. ],
  10. [
  11. "id",
  12. "name",
  13. "year",
  14. ]
  15. );

public supportSequences () inherited from Phalcon\Db\Adapter

Check whether the database system requires a sequence to produce auto-numeric values

public getDescriptor () inherited from Phalcon\Db\Adapter

Return descriptor used to connect to the active database

public string getConnectionId () inherited from Phalcon\Db\Adapter

Gets the active connection unique identifier

public getSQLStatement () inherited from Phalcon\Db\Adapter

Active SQL statement in the object

public getRealSQLStatement () inherited from Phalcon\Db\Adapter

Active SQL statement in the object without replace bound parameters

public array getSQLBindTypes () inherited from Phalcon\Db\Adapter

Active SQL statement in the object