Phalcon - Switching Databases


We have used a MySQL database in our application. If we wanted to change the database software midstream, it would not be too hard, as long as we have the same data structure in our new database.


Configure the web application which will connect to PostgreSQL database.

This can be achieved using the following code. The services will include Phalcon\Db\Adapter\Pdo\Postgresql

use Phalcon\Db\Adapter\Pdo\Postgresql;  

$config = [ 
   'host'     => 'localhost', 
   'dbname'   => 'blog_tutorial', 
   'port'     => 5432, 
   'username' => 'root', 
   'password' => '' 

$connection = new Postgresql($config); 


For implementing SQLite connection, the configuration should be extended with Phalcon\Db\Adapter\Pdo\Sqlite abstract class.

use Phalcon\Db\Adapter\Pdo\Sqlite;  

$connection = new Sqlite(['dbname' => '/tmp/blog_tutorial.sqlite']); 


For implementing Oracle database connection in Phalcon, the configuration should be extended with Phalcon\Db\Adapter\Pdo\Oracle abstract class.


use Phalcon\Db\Adapter\Pdo\Oracle;  

$config = array ( 
   "dbname" => "//localhost/blog_tutorial", 
   "username" => "root", 
   "password" => "" 

$connection = new Phalcon\Db\Adapter\Pdo\Oracle($config);