Laravel 4 on Mac localhost: Can't find driver for SQLSRV

I am trying to connect with Laravel 4 to a SQL Server database. I am getting an error, but I think it is a PHP bug, not a Laravel bug. He speaks PDOException: could not find driver

. I have a driver installed sqlsrv

as another example in a file database.php

. As I said, I think this is a PHP bug, not Laravel.

I am on localhost on my Mac. Do I need to customize something in the file php.ini

? I found another article that said I need to comment on the MySQL driver under PDO. I also couldn't find this line in mine php.ini

. But I still need to connect to the MySQL database. What do I need to change in the file php.ini

?

I found this line:

pdo_mysql.cache_size = 2000

But commenting it out did nothing even after restarting Apache.

+3


source to share


3 answers


The sqlsrv driver is a Windows only driver according to the PHP manual (www.php.net/manual/en/sqlsrv.requirements.php). Therefore, you cannot use this driver for Mac, Linux, Unix, or any other operating system than those listed on this page.

I am assuming you are trying to connect to a remote SQL Server somewhere? If you are on a Mac then SQL Server will not work on your local machine, so I assume the first question is whether you have SQL Server.

Second, from the server running PHP, you will need to connect using FreeTDS or ODBC using FreeTDS.

Since Laravel 4 uses PDO, you need to install FreeTDS and ODBC. Laravel 4 does not use the mssql PHP extension. It uses PDO, so mssql won't take you anywhere with Laravel 4.



If you are using PHP from your Mac I would say that generally you can use 4 different ways:

  • An easy but expensive way: go to the website (www.macupdate.com/app/mac/23152/openlink-odbc-driver-for-sybase) and download and install the OpenLink ODBC driver. This allows new ODBC connections to be created using the Sybase Driver (MSSQL) on the XNIX machine. Here you can go through the installation (wikis.openlinksw.com/dataspace/owiki/wiki/UdaWikiWeb/InstallSybaseExpressOSX). It comes with a 15-day trial, after which you will have to buy it. At the time of this writing, it appears to be priced somewhere between $ 30 and $ 50 depending on the license you choose.

  • More complex but also free: follow http://blog.benjaminwalters.net/?p=10 (slightly out of date) to re-compile FreeTDS support in PHP on Mac (if you're using MAMP)

  • Much better, but also much more efficient, is to find virtual machine host software like VMWare Fusion and install a Linux server like Ubuntu 12.4. Make sure you have apache2 and PHP installed during the installation process, then follow the steps here to get FreeTDS working on your new server machine.

  • Run PHP from Windows Server running SQL Server

The grace will vary with each decision, and there is a learning curve either way. I've been a PHP developer for a long time and it took me a few days to figure out how to connect to SQL Server for the first time from Linux. Fortunately, there are quite a few passes now, and FreeTDS has come a long way since then.

Hope it helps. :)

+6


source


Actually for me it works on my setup. My best advice is to get to Homebrew .

https://github.com/josegonzalez/homebrew-php is where you are going to look for installing PHP and related items. I don't remember exactly what I did, but it wasn't particularly difficult.

You will need FreeTDS first.

brew install freetds

      



Then add Jose's formulas to your homebrew (instructions on the github page). Thereafter

brew install php5x --with-mssql  

brew options php5x

      

if you need more extensions.

+1


source


Based on the comment by John Watson,

I tried step 2 and it doesn't work. check my issue here https://github.com/laravel/laravel/issues/2180

Step 3 is a broken link and I think it is the same with step 2.

I also tried Linux ODBC driver for Laravel (there are 2, google it), both don't work either . Although my simple test php works in both DBLIB and ODBC (compiled using the official unsoft uncc uncc driver).

Step 4 definitely works, BUT you should use IIS for better stability.

This leaves step 1. OR,

Ditch Laravel4 and use the good ol 'AdoDB http://adodb.sourceforge.net/ which I have been using since 2006 and still work fine (albeit not modern Laravel) set it up with the tutorial at http: //docs.moodle .org / 20 / en / Installing_MSSQL_for_PHP

I wonder why they don't build sqlsrv driver for linux too ....

0


source







All Articles