Laravel with mssql (sqlsrv) not connecting

≯℡__Kan透↙ 提交于 2019-12-06 10:08:11

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

  1. Download and install pre-requisites using Homebrew (simplest option):
    FreeTDS: brew install freetds
    autconf: brew install autoconf

  2. Download PHP version source code (I used 5.6.27): http://php.net/releases/

  3. Extract source, open Terminal, and go to folder in command-line

  4. (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.

  1. Type which phpize to confirm that it is using your MAMP installation's PHP

  2. Configure and Make downloaded PHP source:
    ./configure --without-iconv && make

  3. Go to the Extensions folder of the downloaded PHP source:
    cd ext

  4. Go to the MSSQL Extension folder:
    cd mssql

  5. Run phpize

  6. 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.

  1. Go to the Modules folder:
    cd modules

  2. 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/

  3. 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)

  4. Find ; Extensions and at the bottom of this section add:
    extension=mssql.so

  5. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!