Abstract class Phalcon\Db

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. try {
  3. $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
  4. 'host' => '192.168.0.11',
  5. 'username' => 'sigma',
  6. 'password' => 'secret',
  7. 'dbname' => 'blog',
  8. 'port' => '3306',
  9. ));
  10. $result = $connection->query("SELECT * FROM robots LIMIT 5");
  11. $result->setFetchMode(Phalcon\Db::FETCH_NUM);
  12. while ($robot = $result->fetch()) {
  13. print_r($robot);
  14. }
  15. } catch (Phalcon\Db\Exception $e) {
  16. echo $e->getMessage(), PHP_EOL;
  17. }

Constants

integer FETCH_ASSOC

integer FETCH_BOTH

integer FETCH_NUM

integer FETCH_OBJ

Methods

public static setup (unknown $options)

Enables/disables options in the Database component