From The Blog

Using CakePHP without Database Connection

9 October 2011, in CakePHP

Is it possible to use CakePHP framework without using any database connection?

YES

Without much fanfare - here are the steps to trick CakePHP into believing that there is a database even when there is none!

#1 Create a file called dbo_my_dbo_source.php in the directory app/models/datasources/dbo/

Put the following code in this newly created file

  • class DboMyDboSource extends DboSource
  • {
  •     function connect()
  •     {
  •         $this->connected = true;
  •         return $this->connected;
  •     }
  •     function disconnect()
  •     {
  •         $this->connected = false;
  •         return !$this->connected;
  •     }
  • }

#2 Next we need to tell our app to use this dbo source by default - for that edit database.php and as driver put 'my_dbo_source' this is set to 'mysql' by default

'driver' => 'my_dbo_source',

'database'=>'',

#3 Now make sure your models set useTable to false

$useTable = false;

Reference: http://www.sanisoft.com/blog/2008/08/22/using-cakephp-without-a-database/



Post a Comment