Search code examples
phpsql-server-2008cakephpdriver

Making CakePHP work with SQL server 2008


I can call SQL server 2008 from PHP with Microsoft Drivers for PHP for SQL Server But as Sqlsvr driver class is needed to use CakePHP with SQL server 2008, I got the driver file from following repository.

However, when running my test cakephp with following database.php

 <?php
 class DATABASE_CONFIG {

    var $default = array(
    'driver' => 'sqlsvr',
    'host' => 'localhost\EPHP',
    'login' => 'sa',
    'password' => 'xxxxxxx',
    'database' => 'Blog',
    );
  }
  ?> 

I got following error:

Fatal Error (256): ConnectionManager::loadDataSource - Unable to import DataSource class .DboSqlsvr [CORE\cake\libs\model\connection_manager.php, line 185]

Then I have read all the you-cannot-make-cakePHP-work-with-sql-2008 discussions. Is there any resolution by now?

UPDATE: Let me rephrase my question. I would appreciate if someone successfully made CakePHP work with SQL 2008 and tell me the procedure he followed to do that.


Solution

  • After some research, I found this article ( http://book.cakephp.org/view/1652/Plugin-DataSources-and-Datasource-Drivers). Basically, you can not place your driver file in the directory ( \cakephp\cake\libs\model\datasources\dbo) where the "factory" driver files are located. Instead you should place the driver file in following directory of your baked cake.

     your-cake-application\plugins\your-plugin-name\models\datasources\dbo
    

    And then you should change your database.php in config accordingly.

     <?php
     class DATABASE_CONFIG {
    
        var $default = array(
        'driver' => 'your-plugin-name.DboSqlsrv',
        'host' => 'localhost\EPHP',
        'login' => 'sa',
        'password' => 'xxxxxxx',
        'database' => 'Blog',
        );
      }
      ?> 
    

    After this, I could run my cakephp app.