Using Laravel 4 with Microsoft SQL Server 2008


I need to connect a SQL Server 2008 database in Laravel 4. I've been searching and found no solution to the scenario I'm in.

I'm using Laravel using the XAMPP (PHP 5.5.6 --with-mssql) package on MAC OS X 10.9 with FreeTDS running perfectly when I use the mssql_ * functions of php in other applications where I do not use Laravel.

When I make a simple query to BD SQL I get the following error:

  PDOException: could not find driver

My configuration in /app/database.php looks like this:

'default' => 'sqlsrv',

'sqlsrv' => array(      'driver'   => 'sqlsrv',         'host'     => 'ip do servidor',         'database' => 'nome da base',       'username' => 'sa',         'password' => 'senha',      'prefix'   => '',   ),


In php.ini, I uncommented the line:


However, by checking the PHP documentation I found the information: "The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and» Microsoft SQL Server ODBC Driver for Linux. ", ie I have to use the connection through an ODBC Driver? Can not I use FreeTDS in Laravel?

I upgraded Native Client on Server with SQL 2008 to version 11.

I'm still unsuccessful. Could someone help me?

asked by anonymous 20.01.2014 / 17:29

2 answers


After almost two weeks of battle, here I have been able to resolve the issue!

I tried several ways to install the correct driver to make the connection to the bank be established. I went to the in order to manually install pdodblib and make PHP understand that it would need to call FreeTDS over an ODBC connection to connect to the database. No success!

Until a light appeared at the end of the tunnel: a simple post in this blog seemed to mock me ... But in fact it brought me a simple solution.

Through HomeBrew I added two repositories containing the 'Formules' needed to re-compile PHP with MSSQL support.

brew tap homebrew/dupes

And then ...

brew tap josegonzalez/homebrew-php

Now we need to install PHP through the command:

brew install php55 --with-mssql

After completing the installation of all the dependencies, you just have to configure your freetds.conf with the bank information and ... Voila! It works.

28.01.2014 / 19:00

I took a quick look at Google and, according to the stackoverflow in English, your SQL SERVER NATIVE CLIENT should be at least version 11, in order to work with the PDO. Give it a try.

SOURCE: link

EDIT: Also, it's always nice to take a look at the PHP documentation on PDO + SQL SERVER - link

20.01.2014 / 17:44