SQLServer

From DreamFactory
Jump to: navigation, search
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
There are two different drivers you can use to connect to Microsoft SQL. We recommend the sqlsrv driver over dblib/freetds. However dblib/freetds is still supported.
+
There are two different drivers you can use to connect to Microsoft SQL. We '''highly recommend''' the sqlsrv driver over dblib/freetds. However dblib/freetds is still supported.
 
=== SQLSRV ===
 
=== SQLSRV ===
 +
'''Note:''' These instructions were adapted from the official Microsoft PHP SQLSRV repo on Github[https://github.com/Microsoft/msphpsql]. Please consult this repo for additional information about this driver and its implementation options.
 
# Install the ODBC 13 Driver (only support on Ubuntu 15 and 16)
 
# Install the ODBC 13 Driver (only support on Ubuntu 15 and 16)
#* <source lang="bash">$ sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release/ xenial main" > /etc/apt/sources.list.d/mssqlpreview.list'</source>
+
#* <source lang="bash">$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -</source>
#* <source lang="bash">$ sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893</source>
+
#* <source lang="bash">$ sudo sh -c 'curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list'</source>
 
#* <source lang="bash">$ sudo apt-get update</source>
 
#* <source lang="bash">$ sudo apt-get update</source>
#* <source lang="bash">$ sudo apt-get install msodbcsql unixodbc-dev-utf16</source>
+
#* <source lang="bash">$ sudo ACCEPT_EULA=Y apt-get install msodbcsql unixodbc-dev</source>
 
# Install tools used for PECL
 
# Install tools used for PECL
#* <source lang="bash">$ sudo apt-get install php-dev php-pear</source>
+
#* <source lang="bash">$ sudo apt-get install php7.1-dev php-pear</source>
 
# Install sqlsrv and pdo_sqlsr using PECL
 
# Install sqlsrv and pdo_sqlsr using PECL
#* Find the right version number
+
#* sqlsrv on PECL is has been released from development to stable. As of the writing of these instructions, the latest verison 4.3.0.
#** sqlsrv on PECL is still listed as under development so you have to specify the version number. You can get this using the below command. As of the writing of these instructions, the latest verison 4.0.6.
+
#** <source lang="bash">$ sudo pecl install sqlsrv</source>
#** <source lang="bash">$ pecl search sqlsrv</source>
+
#** <source lang="bash">$ sudo pecl install pdo_sqlsrv</source>
#* Install the drivers (use the version number acquired via the previous command)
+
# Create the ini files
#** <source lang="bash">$ sudo pecl install pdo_sqlsrv-4.0.6</source>
+
#* <source lang="bash">$ sudo sh -c 'echo "extension=sqlsrv.so" > /etc/php/7.1/mods-available/sqlsrv.ini'</source>
#** <source lang="bash">$ sudo pecl install sqlsv-4.0.6</source>
+
#* <source lang="bash">$ sudo sh -c 'echo "extension=pdo_sqlsrv.so" > /etc/php/7.1/mods-available/pdo_sqlsrv.ini'</source>
# Enable the drivers in PHP
+
# Enable the extensions in PHP
#* <source lang="bash">$ sudo nano /etc/php/7.0/mods-available/pdo_sqlsrv.ini</source>
+
#* <source lang="bash">$ sudo phpenmod sqlsrv pdo_sqlsrv</source>
#** Edit the file so it reads: <code>extension=pdo_sqlsrv.so</code>
+
#** Save and exit the file
+
#* <source lang="bash">$ sudo nano /etc/php/7.0/mods-available/sqlsrv.ini</source>
+
#** Edit the file so it reads: <code>extension=sqlsrv.so</code>
+
#** Save and exit the file
+
 
# Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
 
# Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
 
#* Nginx
 
#* Nginx
#** <source lang="bash">$ sudo service php7.0-fpm restart && sudo service nginx restart</source>
+
#** <source lang="bash">$ sudo service php7.1-fpm restart && sudo service nginx restart</source>
 
#* Apache
 
#* Apache
 
#** <source lang="bash">$ sudo  service apache2 restart</source>
 
#** <source lang="bash">$ sudo  service apache2 restart</source>
Line 30: Line 26:
 
=== DBLIB/FreeTDS ===
 
=== DBLIB/FreeTDS ===
 
# Install the module using Apt
 
# Install the module using Apt
#* <source lang="bash">$ sudo apt-get install php-sybase</source>
+
#* <source lang="bash">$ sudo apt-get install php7.1-sybase</source>
 
# Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
 
# Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
 
#* Nginx
 
#* Nginx
#** <source lang="bash">$ sudo service php7.0-fpm restart && sudo service nginx restart</source>
+
#** <source lang="bash">$ sudo service php7.1-fpm restart && sudo service nginx restart</source>
 
#* Apache
 
#* Apache
 
#** <source lang="bash">$ sudo  service apache2 restart</source>
 
#** <source lang="bash">$ sudo  service apache2 restart</source>

Latest revision as of 16:16, 20 October 2017

There are two different drivers you can use to connect to Microsoft SQL. We highly recommend the sqlsrv driver over dblib/freetds. However dblib/freetds is still supported.

SQLSRV

Note: These instructions were adapted from the official Microsoft PHP SQLSRV repo on Github[1]. Please consult this repo for additional information about this driver and its implementation options.

  1. Install the ODBC 13 Driver (only support on Ubuntu 15 and 16)
    • $ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    • $ sudo sh -c 'curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list'
    • $ sudo apt-get update
    • $ sudo ACCEPT_EULA=Y apt-get install msodbcsql unixodbc-dev
  2. Install tools used for PECL
    • $ sudo apt-get install php7.1-dev php-pear
  3. Install sqlsrv and pdo_sqlsr using PECL
    • sqlsrv on PECL is has been released from development to stable. As of the writing of these instructions, the latest verison 4.3.0.
      • $ sudo pecl install sqlsrv
      • $ sudo pecl install pdo_sqlsrv
  4. Create the ini files
    • $ sudo sh -c 'echo "extension=sqlsrv.so" > /etc/php/7.1/mods-available/sqlsrv.ini'
    • $ sudo sh -c 'echo "extension=pdo_sqlsrv.so" > /etc/php/7.1/mods-available/pdo_sqlsrv.ini'
  5. Enable the extensions in PHP
    • $ sudo phpenmod sqlsrv pdo_sqlsrv
  6. Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
    • Nginx
      • $ sudo service php7.1-fpm restart && sudo service nginx restart
    • Apache
      • $ sudo  service apache2 restart

DBLIB/FreeTDS

  1. Install the module using Apt
    • $ sudo apt-get install php7.1-sybase
  2. Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
    • Nginx
      • $ sudo service php7.1-fpm restart && sudo service nginx restart
    • Apache
      • $ sudo  service apache2 restart