Tabla de Contenidos

Tema anterior

< Class Phalcon\DI\Service\Builder

Próximo tema

Class Phalcon\Db\Adapter >

Esta página

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


try {

  $connection = new Phalcon\Db\Adapter\Pdo\Mysql(array(
     'host' => '',
     'username' => 'sigma',
     'password' => 'secret',
     'dbname' => 'blog',
     'port' => '3306',

  $result = $connection->query("SELECT * FROM robots LIMIT 5");
  while($robot = $result->fetch()){

} catch(Phalcon\Db\Exception $e){
echo $e->getMessage(), PHP_EOL;



integer FETCH_BOTH

integer FETCH_NUM

integer FETCH_OBJ


public static setup (array $options)

Enables/disables options in the Database component