Using Laravel 4 with Microsoft SQL Server 2008

Asked

Viewed 1,106 times

15

I need to connect a database SQL Server 2008 in Laravel 4. I have been researching and I did not find solution for the scenario in which I am.

I’m using Laravel using the XAMPP (PHP 5.5.6 --with-mssql) package on MAC OS X 10.9 with Freetds working perfectly when I use php’s mssql_* functions in other applications where I don’t use Laravel.

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

Pdoexception: could not find driver

My setting in /app/database.php is this way:

'default' => 'sqlsrv',

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

[Edited]

In php.ini, I decoded the line:

extension=php_pdo_mssql.dll

However, checking the PHP documentation found the information: "The PDO_SQLSRV Extension is only compatible with PHP running on Windows. For Linux, see ODBC and » Microsoft’s SQL Server ODBC Driver for Linux.", or do I have to use the connection via an ODBC Driver? Can’t use Freetds on Laravel?

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

I am still unsuccessful. Could someone help me?

  • 1

    In the phpinfo(), the extension PDO_SQLSRV appears enabled?

  • No. In phpinfo() -> API Extensions, only: mysqli,mysql,pdo_mysql.

  • 2

    Here’s the problem, either the extension is commented on in your php.ini, or it’s not installed.

  • I decoded the line Extension=php_pdo_mssql.dll, but mssql does not appear in the PDO’s list in phpinfo()

  • 1

    Any error message? a dll is in the folder ext?

  • I don’t get any error message when starting Apache...

  • 2

    No use trying to use DLL in OSX. I think you’ll need to recompile php...

  • Trying to help (in English): http://stackoverflow.com/questions/13371281/how-can-i-connect-to-sql-server-from-a-mac-with-php-pdo

  • Thanks @bfavaretto, your comment cleared up a few things and I think I’m close to finding the solution. Has anyone been in the same situation as this and requested changes in Laravel repository in Git. Now I need to find out how Laravel 4 manipulates these parameters in DB config.

Show 4 more comments

2 answers

8


After nearly two weeks of battle, I managed 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 depths seeking to manually install pdodblib and make PHP understand that it would need to call Freetds via an ODBC connection to connect to the database. Unsuccessful!

Until a light appeared at the end of the tunnel: a simple post on this blog seemed to mock me... but in fact he 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 you complete the installation of all dependencies, just configure your freetds.conf with the database information and... Voilá! It Works.

1

  • I had already seen these posts in Stack in English, and by conscience went to check: As I commented above, PDO does not really appear in phpinfo(). I have updated the Native Client of the Server and I still have the same problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.