Abstract class Phalcon\Db

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 is an abstract class. You only can use it with a database adapter like Phalcon\Db\Adapter\Pdo

  1. <?php
  2. use Phalcon\Db;
  3. use Phalcon\Db\Exception;
  4. use Phalcon\Db\Adapter\Pdo\Mysql as MysqlConnection;
  5. try {
  6. $connection = new MysqlConnection(
  7. [
  8. "host" => "192.168.0.11",
  9. "username" => "sigma",
  10. "password" => "secret",
  11. "dbname" => "blog",
  12. "port" => "3306",
  13. ]
  14. );
  15. $result = $connection->query(
  16. "SELECT * FROM robots LIMIT 5"
  17. );
  18. $result->setFetchMode(Db::FETCH_NUM);
  19. while ($robot = $result->fetch()) {
  20. print_r($robot);
  21. }
  22. } catch (Exception $e) {
  23. echo $e->getMessage(), PHP_EOL;
  24. }

Constants

integer FETCH_LAZY

integer FETCH_ASSOC

integer FETCH_NAMED

integer FETCH_NUM

integer FETCH_BOTH

integer FETCH_OBJ

integer FETCH_BOUND

integer FETCH_COLUMN

integer FETCH_CLASS

integer FETCH_INTO

integer FETCH_FUNC

integer FETCH_GROUP

integer FETCH_UNIQUE

integer FETCH_KEY_PAIR

integer FETCH_CLASSTYPE

integer FETCH_SERIALIZE

integer FETCH_PROPS_LATE

Methods

public static setup (array $options)

Enables/disables options in the Database component