Using CakePHP without a database

I enjoy CakePHP’s structure and methods so much that I have started  using it for my non-database driven projects and for prototyping big projects.

However, when no database is present CakePHP throws a warning that it can’t connect to the database. The solution is to create a dummy database connection to convince CakePHP that all is ok. And, it’s as simple as this:

Create a new folder app/models/datasources/dbo

Create a new file at app/models/datasources/dbo/dbo_dummy_db.php and add the following:

1
2
3
4
5
6
7
<?php   
    class DboDummyDb extends DboSource {         
                 function connect()  {                
                          $this->connected = true;
                          return $this->connected;
                  }
            }

In your app/config/database.php find the default connection array – a line that starts $default = array
and replace the line for the driver from
'driver' => 'mysql',
to
'driver' => 'dummy_db',

And that’s all there is to using CakePHP without a database.

4 thoughts on “Using CakePHP without a database

  1. hi, i think you should create the dbo folder as a subfolder of “datasources”
    app/models/datasources/dbo/dbo_dummy_db.php

  2. When I use your script im getting this error:

    Fatal error: Call to undefined method DboDummyDb::_execute() in /directoryToFile/cake/libs/model/datasources/dbo_source.php on line 253

    Im basically connecting to a 3rd party API for all data operations and hence do not need a DB. I just want to use the model for validation and what not. Most of the site seems to work fine, it’s just when I pass an ‘id’ field in via the URL (/business/venue/edit/123456) or use it as the name of a form field I get this error. If I change the name of the form field and do not pass the ‘id’ via the URL I do not get the error BUT I shouldnt have to change the names right? It should just work.

    Any help would be most appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>