Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to point to manual install Microsoft ODBC Driver 13

Tags:

php

pdo

odbc

sqlsrv

I'm attempting to setup the Microsoft ODBC Driver on platform.sh so that the PDO_SQLSRV and SQLSRV PHP extensions are available to me. apt and other sudo commands are limited. However, during the build I can set environment variables such as LD_LIBRARY_PATH.

Here is what I have tried so far.

  1. I downloaded https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/msodbcsql/ and extracted all of the files from the package.
  2. I copied the extracted files to the server
  3. Tried: export LD_LIBRARY_PATH="($pwd):$LD_LIBRARY_PATH" and LD_LIBRARY_PATH="($pwd):$LD_LIBRARY_PATH" /usr/sbin/php-fpm7.0

Still, I get the following error:

SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 13
for SQL Server to communicate with SQL Server. Access the following 
URL to download the ODBC Driver 13 for SQL Server for x86: 
http://go.microsoft.com/fwlink/?LinkId=163712

Update

All dependencies are met when I execute LD_LIBRARY_PATH=$(pwd) ldd libmsodbcsql-13.1.so.4.0. However, when I launch with LD_LIBRARY_PATH="$(pwd):$LD_LIBRARY_PATH" /usr/sbin/php-fpm7.0 I still see the error shown above.

like image 586
TylersSN Avatar asked Feb 07 '17 16:02

TylersSN


People also ask

Where do I install ODBC Drivers?

To install the ODBC driver, you need administrator-level privileges so that the driver can be installed in the C:\Program Files directory.


2 Answers

My guess is that your extension is linked to the wrong libraries.

That said, you don't need a custom extension for that. You can just add this to your .platform.app.yaml:

runtime:
    extensions:
        - mssql

See this page for more information.

like image 98
Florian Margaine Avatar answered Sep 18 '22 12:09

Florian Margaine


Use FreeTDS for your MSSQL driver instead. You will ideally need sudo privileges. Although it is possible to have user specific ODBC configuration files, you would still need to install the base software if it's not already been done.

sudo apt-get install freetds-common freetds-bin unixodbc tdsodbc php5-odbc php5-sybase

Add a connection to: /etc/freetds/freetds.conf

[global]
text size = 64512

[my_connection]
host = SQL_HOSTNAME
port = SQL PORT - possibly 1433 
tds_version = 7.2
encryption = required

Add FreeTDS to your ODBC driver list: /etc/odbcinst.ini

[odbc]
Description     = ODBC driver
Driver          = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup           = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

[FreeTDS]
Description     = FreeTDS
Driver          = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

Finally add the FreeTDS connection to your ODBC config: /etc/odbc.ini The ServerName must match the one used in FreeTDS

[my_connection]
Driver          = FreeTDS
Description     = Uses FreeTDS configuration settings defined in /etc/freetds/freetds.conf
Servername      = my_connection
TDS_Version     = 7.2

[Default]
Driver          = FreeTDS

Now you will be able to use PDO with the ODBC or FreeTDS drivers.

Using FreeTDS directly

$pdo = new PDO($'dblib:host=my_connection', 'username', 'password');

Or using ODBC via FreeTDS

$pdo = new PDO('odbc=my_connection', 'username', 'password');

You might find both drivers have slightly different characteristics so use the one which is most reliable for the queries you are using.

like image 34
Steve E. Avatar answered Sep 19 '22 12:09

Steve E.