# CakePHP & FireBird SQL

I recently gave myself the challenge of developing a web front-end to my work’s CRM system (Customer Relationship Management). Seemed straightforward enough. However the CRM system in question was written at least a decade ago with technologies which are no longer being maintained. The underlying database FireBird SQL (formally Borland InterBase), may have been a good in its hay day but is no contender amongst MySQL, SQL Server, or MSSQL Server, given the support available from vendors and the community.

I am also a big proponent of CakePHP, an easy to learn and simple MVC framework for PHP. One of the big advantages of CakePHP is its excellent object relational mapping (ORM) – the ability to represent objects and relationships contained within a database natively in your application code. I only have to tell CakePHP the name of the table and it will happily work out the schema using a bit of reflection.

I wanted this convenience in creating my front-end to my CRM, however as of version 2.0+, CakePHP no longer natively supports these minority databases. They do however still maintain their datasources plugin which does incorporate the FireBird SQL datasource although this is only compatible up to version 1.3 of CakePHP.

After searching the internet for a decent walk through or tutorial, I came up with very little and so I decided to collate what have learned in this post with the hope that someone else can benefit from it.

Firstly you will need to obtain the datasources plugin from github and stick it in your application’s plugin folder (app/plugins) – make sure you get the master branch and not the 2.0 as it needs to be compatible with your version of CakePHP (1.3 ideally)

The next thing you need to do is edit the databases config file (app/config/database.php):

var \$default= array(
'driver' => 'Datasources.DboFirebird', //references the datasources plugin
'persistent' => false,
'host' => 'localhost', //the host name of your database
'database' => 'C:\\path\\to\\database.gdb', //path to the database - note the double backslashes
'prefix' => '',
//'encoding' => 'utf8',
);

The two important things you should note of is the driver key-value pair which references the datasource plugin namespace, and secondly the double backslashes for the database file path.

All the models you create for your application should now access the corresponding tables through the FireBird SQL connection.

1. mariuz says:

Thanks for the tip I will update my tutorial to 1.3
http://mapopa.blogspot.ro/2008/08/cakephp-tutorial-for-ubuntu-firebird.html

The problem is they switched from native drivers to pdo_* ones
not that Firebird is less known , take a look at sourcefore downloads http://sourceforge.net/projects/firebird/files/stats/timeline?dates=2000-07-31+to+2012-06-23

I will try to convert the driver to pdo
but later in this summer time

• Sam Delaney says:

Thanks Mariuz,

To be honest I don’t give FireBird SQL the credit it deserves probably because it isn’t as mainstream as the others. This does not mean its any less of a database!

2. BUGHUNTER says:

Because of Delphi everywhere in the past 10 or 20 years there are still many softwares which still are using Firebird nowaday – but of course there is no feature that would make this ancient database a good choice in a new project – in any case postgresql or, if very big data, one of the modern destributed systems will be much better. Also look here:
http://stackoverflow.com/questions/1398491/why-not-use-firebird

But it is good to have PDO support for Firebird, so we can get data out of these legacy applications.

BTW if you like CakePHP, what is a dying Framework, if you did not notice, you should really take a look at YII – this brilliant framework is one of the few reasons to still use b0rked PHP for programming nowadays.

3. tonyyip says:

Does this work in CakePHP 2.x? I have been looking firebird database support in PHP framework for a long time but not able to find. Any other PHP framework recommended?
Thanks.

• Sam Delaney says:

Hi Tony,

As of 2.0, you no longer specify the database driver for your configuration, you set the datasource which can be MySQL, PostgreSQL, SQLite, SQL Server.

If you look at the 2.0 branch of the Datasources plugin, Firebird is still on the incompatible list.