Thanks to, which does the equivalent job for Python and which pointed me in the right direction for all this. Linux Install unixODBC, this abstracts database access If I was on SUSE Linux (SLES) I would hit up yast and install the following packages su root yast unixODBC 2.2.11 2.2.
Mac OS X instructions lower down but the full post should help it all sink in.
If any of this doesn't work for you, first check that the freetds installation is correct using: tsql -S myserver -U myusername -P mypasswordĪnd then check that the ODBC specifications are OK using: isql -v myds myusername mypassword Assuming you have a username and password with some kind of access to a MSSQL server, this might help you. This creates a data source called myds pointing at your database, enabling you to connect with the following PHP: $conn = new PDO('odbc:myds', 'myusername', 'mypassword') This tells the freetdc library where to find your server.ĭescription = Test for SQL Server on Azure This tells the odbc library where to find its odbc driver. Next, you need to include some lines in your configuration files:
It's important to remember to open the firewall to your client IP address, which you do on the server.įirst step is to install freetds with the ODBC driver, and its PHP connector (change php56 to the correct version of your PHP): sudo port install freetds +odbc I've started by creating an Azure SQL Database called mydb on a server with a name of. I'm using OS X 10.11.6 (El Capitan) with Macports, PHP5.6. I've succeeded in connecting using a different stack: freetds,odbc,pdo. Note that Microsoft have published a PHP7 extension for this, but if you're still on PHP5.x, that doesn't help you. $ sudo cp modules/pdo_dblib.so /usr/lib/php/extensions/no-debug-non-zts-20121212ĩ.- Connect using the dblib dsn: $pdo = new PDO("dblib:host=$dbhost dbname=$dbname","$dbuser","$dbpwd")
$ brew install autoconfĤ.- Install FreeTDS $ brew install freetdsĥ.- Download your version of PHP Source and uncompress it.Ħ.- Build the PDO DBLIB extension (Example for PHP 5.5.14) $ cd php-5.5.14/ext/pdo_dblib It worked perfect with OS X El Capitan, Bitnami with PHP 7.ġ.- Install XCode $ xcode-select -installģ.- Install autoconf using Homebrew. You can follow these instructions (ignoring the mssql.so extension) to connect very easily: Where $dbhost is the name from the nf fileĪfter looking at many threads, I've found that the best way to connect to MSSQL from Mac OS X with PHP 7 or older is to use dblib. Then you need to use dblib, not mssql, as the PDO driver: $pdo = new PDO("dblib:host=$dbhost dbname=$dbname", Once it's configured you should be able to run something like this from the command line and connect: tsql -S xyz -U username -P password # Define a connection to the MSSQL server.įreeTDS configuration is the first half of the answer. # Try setting 'text size' to a more reasonable limit # is trying to allocate a huge buffer for a TEXT field. # If you get out-of-memory errors, it may mean that your client # (setting this to /tmp is insecure on a multi-user system) # Whether to write a TDSDUMP file for diagnostic purposes Here is my /etc/freetds/nf file (the only part I added was at the very end for the XYZ server): I use FreeTDS to connect to Microsoft SQL servers from a Linux server and it looks like the person in the link above has used FreeTDS to connect from a Mac.