I was working on laravel with mysql it was working fine. But I have another scenario now. I need to connect the laravel to ms sql database which is reside on windows server. I have used the following code to connect to the DB app/config/database.php
'default' => 'sqlsrv',
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'IP ADDRESS',
'database' => 'DB Name',
'username' => 'Username',
'password' => 'password',
'prefix' => '',
),
but its showing error saying that
PDOException
could not find driver
So please can any one help me to solve this ?
Thank you
Are you using homestead?
I had that exact same problem, using MAMP. The driver was missing from my server, so I ended up switching to homestead and installing freetds there.
For Linux homestead:
First, ssh into your box vagrant ssh from the Homestead folder.
Command : vagrant ssh
Install the Sybase package for enabling the support for PDO and Mssql. Command : sudo apt-get install php7.0-sybase
then run php -m on ssh to make sure pdo_dblib is enable.
For Windows:
you need to manually install this extension. You can download the driver from [Microsoft's website][1].
After extracting the files, please copy them to your PHP's ext directory. To make PHP load the extension, just add the following line to your PHP.ini (this is for the non-thread safe version of PHP, which you are most likely using when you have installed PHP to use IIS FastCGI, which we recommend):
extension=php_sqlsrv.dll
And restart your Apache
To extend @AmitChaudhary's answer:
For Mac OSX using MAMP
Download and install pre-requisites using Homebrew (simplest option):
FreeTDS: brew install freetds
autconf: brew install autoconf
Download PHP version source code (I used 5.6.27): http://php.net/releases/
Extract source, open Terminal, and go to folder in command-line
(Optional) Temporarily add your MAMP's PHP installation to the Path:
export PATH=/Applications/MAMP/bin/php/php5.6.27/bin:$PATH
Make sure you change the version number to whatever you're using.
Type which phpize
to confirm that it is using your MAMP installation's PHP
Configure and Make downloaded PHP source:
./configure --without-iconv && make
Go to the Extensions folder of the downloaded PHP source:
cd ext
Go to the MSSQL Extension folder:
cd mssql
Run phpize
Configure Extension using FreeTDS:
./configure --with-mssql=/usr/local/Cellar/freetds/1.00.23/ && make
Confirm if this is your correct FreeTDS version, it will give you an error if it can't find it.
Go to the Modules folder:
cd modules
Copy the mssql.so
module to your MAMP's Extension folder (for me this was) at:
cp mssql.so /Applications/MAMP/bin/php/php5.6.27/lib/php/extensions/no-debug-non-zts-20131226/
Within MAMP, look for the Edit Templates menu option (depending what version of MAMP, it should be under the MAMP menu or available in MAMP Pro via a button)
Find ; Extensions
and at the bottom of this section add:
extension=mssql.so
Restart your MAMP Apache server and you should be good to go!
I literally just did this but struggled to find a decent walkthrough to job my memory so hopefully this helps someone else (or probably me) in the future.
Cheers
GB.