English 中文(简体)
Phalcon - Switching Databases
  • 时间:2024-12-22

Phalcon - Switching Databases


Previous Page Next Page  

We have used a MySQL database in our apppcation. 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.

PostgreSQL

Configure the web apppcation which will connect to PostgreSQL database.

This can be achieved using the following code. The services will include PhalconDbAdapterPdoPostgresql

use PhalconDbAdapterPdoPostgresql;  

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

$connection = new Postgresql($config); 

SQLite

For implementing SQLite connection, the configuration should be extended with PhalconDbAdapterPdoSqpte abstract class.

<?php  
 
use PhalconDbAdapterPdoSqpte;  

$connection = new Sqpte([ dbname  =>  /tmp/blog_tutorial.sqpte ]); 

Oracle

For implementing Oracle database connection in Phalcon, the configuration should be extended with PhalconDbAdapterPdoOracle abstract class.

<?php  

use PhalconDbAdapterPdoOracle;  

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

$connection = new PhalconDbAdapterPdoOracle($config); 
Advertisements