1

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.

4
  • 1
    Which version of CakePHP are you using? Commented Aug 7, 2011 at 8:05
  • 1
    Have you tried this? github.com/cakephp/datasources Commented Aug 7, 2011 at 8:20
  • Arjan, I have whatever the lastest version is (1.3.11). Commented Aug 7, 2011 at 18:43
  • RSK yup, That's the first thing I did and got the same error. Commented Aug 7, 2011 at 18:51

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm actually have the same problem you had previously. I've put dbo_sqlsrv.php in my_site\plugins\plugin_name\models\datasources\dbo. I also set up database.php as you have in this post. Is there anything else (code, external files, etc.)? It still doesn't work for me. I get an error that says SQL Error: An invalid parameter was passed to sqlsrv_query.
1

Assuming you have the datasources in the folder app/model/datasource/dbo_sqlsrv.php load it like this:

  <?php
 class DATABASE_CONFIG {

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

The difference is in the 'driver' vs 'datasource' keyword

4 Comments

José, have you ever made this (cakephp with sql server 2008) work? Unfortunately, I tried it before, it didn't work. And out of desperation, I just now did it again in vain.
Yes, if you keep getting the same error is because you have the datasource placed in a wrong location. Where is it located?
I have the file in the place where you suggested. d:\cakePHP\app\models\datasources\dbo_sqlsrv.php
Jose, although your file location was not right (I guess driver does not work as datasource any more), your tip on location of the file shed some light and I eventually fixed the problem. For that, + 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.