I am trying to connect mssql server to PHP 7.0.8 through MAMP. I have tried using freetds. On some blog people are saying to use pdo_dblib.so
extension but it's not working.
Please guide me through the process of connection.
I am trying to connect mssql server to PHP 7.0.8 through MAMP. I have tried using freetds. On some blog people are saying to use pdo_dblib.so
extension but it's not working.
Please guide me through the process of connection.
For those who still have this problem:
/Applications/MAMP/bin/php/php7.2.1/bin/pecl install sqlsrv pdo_sqlsrv
Edit php.ini:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
If necessary, use brew install autoconf
if you don't have it already.
While the answers posted by Vague Space and Pedro Santiago helped, I still think the answers are a bit lacking and incomplete… Or ask you to do too much. Honestly the official Microsoft instructions are overkill when they state you need to install their Docker image of SQL Server and such? C’mon… Most people just need the drivers installed to make a connection.
So here is my answer based on my experience installing the pdo_sqlsrv.so
and sqlsrv.so
modules in MAMP (version 5.2) but should work for most any MAMP version that supports some flavor of PHP 7.
.bash_profile
so MAMP’s binaries and libraries are a part of your $PATH
settings.First, adjust your .bash_profile
so the MAMP stuff is in there; makes it easier to launch and work with MAMP specific binaries and ensures MAMP libraries are checked when doing things like installing new modules like this.
The way I like to do it is like this; set $MAMP_BIN
and $MAMP_PHP
variables like this and then rebuild the $PATH
variables:
# MAMP stuff.
export MAMP_BIN="/Applications/MAMP/Library/bin";
export MAMP_PHP="/Applications/MAMP/bin/php/php7.2.10/bin";
# Final $PATH setting.
export PATH="/usr/local/bin:/usr/local/sbin:$MAMP_BIN:$MAMP_PHP:$PATH";
Save it and just log out of the Terminal session and back in, or just resource the .bash_profile
like this:
source ~/.bash_profile
With that done, let’s install the core Microsoft ODBC binary stuff.
Do this to install the core ODBC stuff on macOS; be sure to have Homebrew installed:
brew tap microsoft/SQLSRV-release https://github.com/Microsoft/homebrew-SQLSRV-release
brew update
brew install --no-sandbox msodbcsql17 SQLSRV-tools
Then when that’s done, go ahead and install the Unix ODBC stuff like this:
brew install unixodbc
Now install the actual PHP modules via PECL:
pecl install sqlsrv pdo_sqlsrv
With the modules installed, add them to the php.ini
file in MAMP so PHP can recognize it. For PHP 7.2.10 on MAMP 5.x it should be located here:
/Applications/MAMP/bin/php/php7.2.10/conf/php.ini
And just add these config lines to the bottom of the file:
; Enable 'Microsoft Drivers for PHP for SQL Server' extension module
extension = sqlsrv.so
extension = pdo_sqlsrv.so
; Configuration
;sqlsrv.WarningsReturnAsErrors = 1
;sqlsrv.LogSeverity = 0
;sqlsrv.LogSubsystems = 0
;sqlsrv.ClientBufferMaxKBSize = 10240
;pdo_sqlsrv.log_severity = 0
;pdo_sqlsrv.client_buffer_max_kb_size = 10240
Note, most tutorials—and even PECL when you install the modules—simply mention adding extension = sqlsrv.so
and extension = pdo_sqlsrv.so
to the php.ini
config, but these config options are the ones that RedHat has when installing the PHP SQLSRV via the Remi repo. Yeah, most of them are commented out but I still like having it there for reference.
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
, brew update
and then brew install msodbcsql17 mssql-tools
–
Jocularity pecl install sqlsrv pdo_sqlsrv
fail with autom4te: need GNU m4 1.4 or later
, which was solved by following this post: superuser.com/questions/668746/… (with a slight alteration) –
Jocularity pdo_sqlsrv.so
and sqlsrv.so
into your MAMP's PHP extension directory. Mine was located at /Applications/MAMP/bin/php/php7x.x/lib/php/extensions/no-debug-foo-bar
Edit your php.ini file to include the new extensions:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
Restart your MAMP servers.
having just done this in 2019 with MAMPPRO4 on windows 10 (follow upto step 4 to test that you are connected and then do point 9 ) point 5 onwards is for changing the path in the command line
download dll files from microsoft https://www.microsoft.com/en-gb/download/details.aspx?id=20098
follow the instruction after running the exe file and place the dll files into the extension directory of the php version that you are using eg: MAMP/bin/php/php7.1.29/ext
check phpinfo for the Loaded Configuration File of the php.ini file
add the 2 dll files depending on your requirements (I wasted time by using the 64.dll) make sure you are using ts(thread safe) not nts(none thread safe) in the file name of the dll
extension=php_sqlsrv_71_ts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
in control panel search for advanced system settings and click
click Environment Variables
under system variables not user variables click path and click edit
click new and add C:\MAMP\bin\php\php7.1.29 (Edit this to your path)
restart MAMP
open a new command line an enter php -v you should see the php version displayed
© 2022 - 2024 — McMap. All rights reserved.