From 57c83525a3e7deb448fb44ce857423f13bb4138c Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 11 Jul 2017 17:26:02 -0700 Subject: [PATCH 1/8] Updated readme --- README.md | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 75b2a438..4cbec747 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ You must first be able to build PHP 7 without including these extensions. For h 5. To install the resulting build, run `nmake install` or just copy php_sqlsrv.dll and/or php_pdo_sqlsrv.dll to your PHP extension directory. -This software has been compiled and tested under PHP 7.0.8 using the Visual C++ 2015 compiler. +This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. ## Install (Windows) @@ -80,7 +80,7 @@ This software has been compiled and tested under PHP 7.0.8 using the Visual C++ 3. Restart the Web server. ## Install (UNIX) -The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7 and Mac OS X. To see how to get PHP SQLSRV drivers running on Debian, please visit [Wiki](https://github.com/Microsoft/msphpsql/wiki/Dockerfile-for-getting-pdo_sqlsrv-for-PHP-7.0-on-Debian-in-3-ways). Note that Debian is not officially supported and this instruction hasn't been tested in our test lab. +The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7 and Mac OS X. To see how to get PHP SQLSRV drivers running on Debian, please visit [Wiki](https://github.com/Microsoft/msphpsql/wiki/Dockerfile-for-getting-pdo_sqlsrv-for-PHP-7.0-on-Debian-in-3-ways). Note, however, that Debian is not officially supported and these instructions have not been tested in our test lab. ### Step 1: Install PHP7+ @@ -209,13 +209,18 @@ The following instructions assume a clean environment and show how to install PH brew install mssql-tools brew install autoconf -*Note: You need to make sure you install PHP 7+ before you proceed to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. +*Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. ### Step 3: Install the Microsoft PHP Drivers for SQL Server -*Note: The first step is not required in Mac OS X. PECL installs the stable version when version is not specified. You may run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. Drivers are Mac-compatible starting from `4.1.7preview` release. +*Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. + +On Ubuntu systems only, run: sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system + +On all systems, run: + sudo pecl install sqlsrv sudo pecl install pdo_sqlsrv @@ -236,7 +241,10 @@ The following instructions assume a clean environment and show how to install PH **RedHat** - sudo yum install httpd + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini **Mac OS X** @@ -257,7 +265,10 @@ The following instructions assume a clean environment and show how to install PH **RedHat** - sudo yum install httpd + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini **Mac OS X** @@ -278,10 +289,10 @@ The following instructions assume a clean environment and show how to install PH sudo apachectl restart -*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, do this `sudo setsebool -P httpd_can_network_connect_db 1` +*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` ### Step 6: Create your sample app -Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code in tetsql.php and change the servername, username, password and databasename. +Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into tetsql.php and change the servername, username, password and databasename. Date: Wed, 12 Jul 2017 16:30:33 -0700 Subject: [PATCH 2/8] Updated readme Debian install instructions --- README.md | 61 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4cbec747..8126f7c3 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the 3. Restart the Web server. ## Install (UNIX) -The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7 and Mac OS X. To see how to get PHP SQLSRV drivers running on Debian, please visit [Wiki](https://github.com/Microsoft/msphpsql/wiki/Dockerfile-for-getting-pdo_sqlsrv-for-PHP-7.0-on-Debian-in-3-ways). Note, however, that Debian is not officially supported and these instructions have not been tested in our test lab. +The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7, Debian 8, and Mac OS X. ### Step 1: Install PHP7+ @@ -93,14 +93,12 @@ The following instructions assume a clean environment and show how to install PH apt-get update apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml re2c gcc g++ - **Ubuntu 16.04** sudo su apt-get update apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml re2c gcc g++ - **RedHat 7** sudo su @@ -112,6 +110,16 @@ The following instructions assume a clean environment and show how to install PH yum update yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + curl https://www.dotdeb.org/dotdeb.gpg | apt-key add - + echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + apt-get update + apt-get install php7.0 php-pear php7.0-dev php7.0-xml -y --allow-unauthenticated + **Mac OS X** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -126,7 +134,6 @@ The following instructions assume a clean environment and show how to install PH #### PHP 7.1 - **Ubuntu 16.04** sudo su @@ -135,7 +142,7 @@ The following instructions assume a clean environment and show how to install PH apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml **RedHat 7** - + sudo su wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm @@ -144,7 +151,16 @@ The following instructions assume a clean environment and show how to install PH yum-config-manager --enable remi-php71 yum update yum install php php-pdo php-xml php-pear php-devel - + +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg + echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list + apt-get update + apt-get install php7.1 php-pear php7.1-dev php7.1-xml -y --allow-unauthenticated + **Mac OS X** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -160,7 +176,6 @@ The following instructions assume a clean environment and show how to install PH ### Step 2: Install Prerequisites - **Ubuntu 15.10** sudo su @@ -174,7 +189,6 @@ The following instructions assume a clean environment and show how to install PH echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc - **Ubuntu 16.04** sudo su @@ -200,7 +214,20 @@ The following instructions assume a clean environment and show how to install PH echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc - + +**Debian 8** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list + apt-get install -y locales + echo "en_US.UTF-8 UTF-8" > /etc/locale.gen + locale-gen + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql + sudo apt-get install unixodbc-dev + **Mac OS X** brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release @@ -215,7 +242,7 @@ The following instructions assume a clean environment and show how to install PH *Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. -On Ubuntu systems only, run: +On Ubuntu and Debian systems only, run: sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system @@ -228,7 +255,7 @@ On all systems, run: #### PHP 7.0 -**Ubuntu** +**Ubuntu and Debian** sudo su apt-get install libapache2-mod-php7.0 apache2 @@ -237,8 +264,7 @@ On all systems, run: a2enmod php7.0 echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini - exit - + **RedHat** sudo su @@ -252,7 +278,7 @@ On all systems, run: #### PHP 7.1 -**Ubuntu** +**Ubuntu and Debian** sudo su apt-get install libapache2-mod-php7.1 apache2 @@ -261,8 +287,7 @@ On all systems, run: a2enmod php7.1 echo "extension=sqlsrv.so" >> /etc/php/7.1/apache2/php.ini echo "extension=pdo_sqlsrv.so" >> /etc/php/7.1/apache2/php.ini - exit - + **RedHat** sudo su @@ -277,7 +302,7 @@ On all systems, run: ### Step 5: Restart Apache to load the new php.ini file -**Ubuntu** +**Ubuntu and Debian** sudo service apache2 restart @@ -292,7 +317,7 @@ On all systems, run: *Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` ### Step 6: Create your sample app -Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into tetsql.php and change the servername, username, password and databasename. +Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into testsql.php and change the servername, username, password and databasename. Date: Wed, 12 Jul 2017 16:55:05 -0700 Subject: [PATCH 3/8] Updated readme FAQ --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8126f7c3..a4b3cfd4 100644 --- a/README.md +++ b/README.md @@ -435,11 +435,11 @@ Thank you! **Q:** What's next? -**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing frequent updates. +**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing previews of upcoming releases frequently. **Q:** Is Microsoft taking pull requests for this project? -**A:** Yes. +**A:** Yes. Please submit pull requests to the **dev** branch and not the *master** branch. From f521282a636074d4de3bb9f3e624d1488a4f0c6b Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Wed, 12 Jul 2017 16:55:38 -0700 Subject: [PATCH 4/8] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4b3cfd4..dcacd284 100644 --- a/README.md +++ b/README.md @@ -439,7 +439,7 @@ Thank you! **Q:** Is Microsoft taking pull requests for this project? -**A:** Yes. Please submit pull requests to the **dev** branch and not the *master** branch. +**A:** Yes. Please submit pull requests to the **dev** branch and not the **master** branch. From 9aff63ecb46b11d3d99a6799e06e7c4a5c265e24 Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Wed, 12 Jul 2017 18:21:48 -0700 Subject: [PATCH 5/8] Tweaked a few commands --- README.md | 984 +++++++++++++++++++++++++++--------------------------- 1 file changed, 492 insertions(+), 492 deletions(-) diff --git a/README.md b/README.md index dcacd284..f59f8bdd 100644 --- a/README.md +++ b/README.md @@ -1,492 +1,492 @@ -# Microsoft Drivers for PHP for SQL Server - -**Welcome to the Microsoft Drivers for PHP for SQL Server PHP 7** - -The Microsoft Drivers for PHP for SQL Server are PHP extensions that allow for the reading and writing of SQL Server data from within PHP scripts. The SQLSRV extension provides a procedural interface while the PDO_SQLSRV extension implements PDO for accessing data in all editions of SQL Server 2008 R2 and later (including Azure SQL DB). These drivers rely on the Microsoft ODBC Driver for SQL Server to handle the low-level communication with SQL Server. - -This release contains the SQLSRV and PDO_SQLSRV drivers for PHP 7 with improvements on both drivers and some limitations (see Limitations below for details). Upcoming release(s) will contain more functionality, bug fixes, and more (see Plans below for more details). - -SQL Server Team - - -## Take our survey - -Thank you for taking time to take our February survey. Let us know how we are doing and how you use PHP by taking our March pulse survey: - - - -### Status of Most Recent Builds -| AppVeyor (Windows) |Travis CI (Linux) | Coverage Status -|-------------------------|--------------------------| ------------------ -| [![av-image][]][av-site]| [![tv-image][]][tv-site] |[![Coverage Status][]][coveralls-site] - -[av-image]: https://ci.appveyor.com/api/projects/status/github/Microsoft/msphpsql?branch=dev&svg=true -[av-site]: https://ci.appveyor.com/project/Microsoft-PHPSQL/msphpsql -[tv-image]: https://travis-ci.org/Microsoft/msphpsql.svg?branch=dev -[tv-site]: https://travis-ci.org/Microsoft/msphpsql/ -[Coverage Status]: https://coveralls.io/repos/github/Microsoft/msphpsql/badge.svg?branch=dev -[coveralls-site]: https://coveralls.io/github/Microsoft/msphpsql?branch=dev - -## Get Started - -* [**Ubuntu + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu) -* [**RedHat + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel) -* [**Windows + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows) -* [**Docker**](https://hub.docker.com/r/lbosqmsft/mssql-php-msphpsql/) - - -## Announcements - - Please visit the [blog][blog] for more announcements. - - -## Build (Windows) - -Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Azure/msphpsql/releases) - -#### Prerequisites - -You must first be able to build PHP 7 without including these extensions. For help with doing this, see the [official PHP website][phpbuild] for building your own PHP on Windows. - -#### Compile the drivers - -1. Copy the sqlsrv and/or pdo_sqlsrv source code directory from this repository into the ext subdirectory. - -2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. - -3. Run `configure.bat --with-odbcver=0x0380 and the desired driver options (as below) [plus other options such as --disable-zts for the Non Thread Safe build]` to generate the makefile. You can run `configure.bat --help` to see what other options are available. - * For SQLSRV use: `--enable-sqlsrv=shared` - * For PDO_SQLSRV use: `--enable-pdo=shared --with-pdo-sqlsrv=shared` - -4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. - -5. To install the resulting build, run `nmake install` or just copy php_sqlsrv.dll and/or php_pdo_sqlsrv.dll to your PHP extension directory. - -This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. - -## Install (Windows) - -#### Prerequisites - -- A Web server such as Internet Information Services (IIS) is required. Your Web server must be configured to run PHP -- [Microsoft ODBC Driver 11][odbc11] or [Microsoft ODBC Driver 13][odbc13] - -#### Enable the drivers - -1. Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install). - -2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"` - -3. Restart the Web server. - -## Install (UNIX) -The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7, Debian 8, and Mac OS X. - -### Step 1: Install PHP7+ - -#### PHP 7.0 - -**Ubuntu 15.04, Ubuntu 15.10** - - sudo su - sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' - apt-get update - apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml re2c gcc g++ - -**Ubuntu 16.04** - - sudo su - apt-get update - apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml re2c gcc g++ - -**RedHat 7** - - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php70 - yum update - yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc - -**Debian 8** - - sudo su - apt-get install curl apt-transport-https - curl https://www.dotdeb.org/dotdeb.gpg | apt-key add - - echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list - echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list - apt-get update - apt-get install php7.0 php-pear php7.0-dev php7.0-xml -y --allow-unauthenticated - -**Mac OS X** - - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php70 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile - -#### PHP 7.1 - -**Ubuntu 16.04** - - sudo su - add-apt-repository ppa:ondrej/php - apt-get update - apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml - -**RedHat 7** - - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php71 - yum update - yum install php php-pdo php-xml php-pear php-devel - -**Debian 8** - - sudo su - apt-get install curl apt-transport-https - wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg - echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list - apt-get update - apt-get install php7.1 php-pear php7.1-dev php7.1-xml -y --allow-unauthenticated - -**Mac OS X** - - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php71 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile - - -### Step 2: Install Prerequisites - -**Ubuntu 15.10** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**Ubuntu 16.04** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**RedHat 7** - - sudo su - curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo - exit - sudo yum update - sudo yum remove unixODBC-utf16-devel #to avoid conflicts - sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools - sudo yum install unixODBC-devel - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**Debian 8** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list - apt-get install -y locales - echo "en_US.UTF-8 UTF-8" > /etc/locale.gen - locale-gen - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql - sudo apt-get install unixodbc-dev - -**Mac OS X** - - brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release - brew update - brew install msodbcsql - brew install mssql-tools - brew install autoconf - -*Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. - -### Step 3: Install the Microsoft PHP Drivers for SQL Server - -*Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. - -On Ubuntu and Debian systems only, run: - - sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system - -On all systems, run: - - sudo pecl install sqlsrv - sudo pecl install pdo_sqlsrv - -### Step 4: Install and Configure Apache - -#### PHP 7.0 - -**Ubuntu and Debian** - - sudo su - apt-get install libapache2-mod-php7.0 apache2 - a2dismod mpm_event - a2enmod mpm_prefork - a2enmod php7.0 - echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini - echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini - -**RedHat** - - sudo su - yum install httpd - echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini - echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini - -**Mac OS X** - - (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf - -#### PHP 7.1 - -**Ubuntu and Debian** - - sudo su - apt-get install libapache2-mod-php7.1 apache2 - a2dismod mpm_event - a2enmod mpm_prefork - a2enmod php7.1 - echo "extension=sqlsrv.so" >> /etc/php/7.1/apache2/php.ini - echo "extension=pdo_sqlsrv.so" >> /etc/php/7.1/apache2/php.ini - -**RedHat** - - sudo su - yum install httpd - echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini - echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini - -**Mac OS X** - - (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf - - -### Step 5: Restart Apache to load the new php.ini file - -**Ubuntu and Debian** - - sudo service apache2 restart - -**RedHat** - - sudo apachectl restart - -**Mac OS X** - - sudo apachectl restart - -*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` - -### Step 6: Create your sample app -Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into testsql.php and change the servername, username, password and databasename. - - "yourDatabase", - "Uid" => "yourUsername", - "PWD" => "yourPassword" - ); - //Establishes the connection - $conn = sqlsrv_connect( $serverName, $connectionOptions ); - if( $conn === false ) { - die( FormatErrors( sqlsrv_errors())); - } - //Select Query - $tsql= "SELECT @@Version as SQL_VERSION"; - //Executes the query - $getResults= sqlsrv_query( $conn, $tsql ); - //Error handling - - if ( $getResults == FALSE ) - die( FormatErrors( sqlsrv_errors())); - ?> -

Results :

- "); - } - sqlsrv_free_stmt( $getResults ); - function FormatErrors( $errors ) - { - /* Display errors. */ - echo "Error information:
"; - - foreach ( $errors as $error ) - { - echo "SQLSTATE: ".$error['SQLSTATE']."
"; - echo "Code: ".$error['code']."
"; - echo "Message: ".$error['message']."
"; - } - } - ?> - -### Step 7: Run your sample app - -Go to your browser and type in http://localhost/testsql.php (http://localhost:8080/testsql.php on Mac) -You should be able to connect to your SQL Server/Azure SQL Database. - -The drivers are distributed as shared binary extensions for PHP. They are available in thread safe (*_ts.so) and-non thread safe (*_nts.so) versions. The source code for the drivers is also available, and you can choose whether to compile them as thread safe or non-thread safe versions. The thread safety configuration of your web server will determine which version you need. - -## Sample Code -For samples, please see the sample folder. For setup instructions, see [here](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-php-simple). - -## Limitations - -- This release contains the PHP 7 port of the SQLSRV and PDO_SQLSRV drivers, and does not provide backwards compatibility with PHP 5. -- Binding output parameters using emulate prepare is not supported. -- Linux - - ODBC 3.52 is supported but not 3.8. - - Connection using named instances using '\' is not supported. - - Local encodings other than UTF-8 are not supported, and SQLSRV_ENC_CHAR only supports ASCII characters with ASCII code of 0 to 127. - -## Known Issues -- User defined data types and SQL_VARIANT. -- Binary column binding with emulate prepare ([issue#140](https://github.com/Microsoft/msphpsql/issues/140) ) -- Linux - - The following features are not supported with connection pooling: - - PDO is only supported with unixODBC 2.3.1. - - Unicode connection strings - - sqlsrv_server_info and sqlsrv_client_info return false - - In certain scenarios a generic error message maybe returned instead of a specific error when pooling is disabled - - When retrieving data from columns with a data type of XML, varchar(max), nvarchar(max), or varbinary(max) no data maybe returned or the data maybe truncated depending on the length of the data in the source table. - -## Version number -Version number of PHP drivers follow the [semantic versioning](http://semver.org/): - -Given a version number MAJOR.MINOR.PATCH, - - - MAJOR version is incremented when an incompatible API changes is made, - - MINOR version is incremented when a functionality in a backwards-compatible manner is added, and - - PATCH version is incremented when backwards-compatible bug fixes are made. - -version number MAY have trailing pre-release version to indicate the stability, and/or build meta data. - -- Pre-release version is denoted by hyphen followed by `preview` or `rc` keyword and may be followed by a series of dot separated identifiers. Production quality releases do not contain the pre-release version. `preview` has lower precedence than `rc`. Example of precedence: *preview < preview.1 < rc < rc.1*. -*Note that PECL package version does not have the hyphen before pre-release version, due to restrictions in PECL. Example of PECL package version: 1.2.3preview* -- Build metadata MAY be denoted by a plus sign followed by 4 digits, such as `1.2.3-preview+5678` or `1.2.3+5678`. Build meta data does NOT figure into the precedence order. - - - -## Future Plans -- Expand SQL 16 Feature Support (example: Always Encrypted). -- Add More Verification/Fundamental Tests. -- Bug Fixes. - -## Guidelines for Reporting Issues -We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you: - -- Report each issue as a new issue (but check first if it's already been reported) -- Try to be detailed in your report. Useful information for good bug reports include: - * What you are seeing and what the expected behaviour is - * Can you connect to SQL Server via `sqlcmd`? - * Which driver: SQLSRV or PDO_SQLSRV? - * Environment details: e.g. PHP version, thread safe (TS) or non-thread safe (NTS), 32-bit &/or 64-bit? - * Table schema (for some issues the data types make a big difference!) - * Any other relevant information you want to share -- Try to include a PHP script demonstrating the isolated problem. - -Thank you! - -## FAQs -**Q:** Can we get dates for any of the Future Plans listed above? - -**A:** At this time, Microsoft is not able to announce dates. We are working extremely hard to release future versions of the driver. We will share future plans as appropriate. - -**Q:** What's next? - -**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing previews of upcoming releases frequently. - -**Q:** Is Microsoft taking pull requests for this project? - -**A:** Yes. Please submit pull requests to the **dev** branch and not the **master** branch. - - - -## License - -The Microsoft Drivers for PHP for SQL Server are licensed under the MIT license. See the LICENSE file for more details. - -## Code of conduct - -This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. - -## Resources - -**Documentation**: [MSDN Online Documentation][phpdoc]. - -**Team Blog**: Browse our blog for comments and announcements from the team in the [team blog][blog]. - -**Known Issues**: Please visit the [project on Github][project] to view outstanding [issues][issues] and report new ones. - -[blog]: http://blogs.msdn.com/b/sqlphp/ - -[project]: https://github.com/Azure/msphpsql - -[issues]: https://github.com/Azure/msphpsql/issues - -[phpweb]: http://php.net - -[phpbuild]: https://wiki.php.net/internals/windows/stepbystepbuild - -[phpdoc]: http://msdn.microsoft.com/library/dd903047%28SQL.11%29.aspx - -[odbc11]: https://www.microsoft.com/download/details.aspx?id=36434 - -[odbc13]: https://www.microsoft.com/download/details.aspx?id=50420 - -[odbcLinux]: https://msdn.microsoft.com/library/hh568454(v=sql.110).aspx - -[phpazure]: https://azure.microsoft.com/documentation/articles/sql-database-develop-php-simple-windows/ - -[PHPMan]: http://php.net/manual/install.unix.php - -[LinuxDM]: https://msdn.microsoft.com/library/hh568449(v=sql.110).aspx - -[httpd_source]: http://httpd.apache.org/ - -[apr_source]: http://apr.apache.org/ - -[httpdconf]: http://php.net/manual/en/install.unix.apache2.php - -[ODBCinstallers]: https://blogs.msdn.microsoft.com/sqlnativeclient/2016/09/06/preview-release-of-the-sql-server-cc-odbc-driver-13-0-0-for-linux +# Microsoft Drivers for PHP for SQL Server + +**Welcome to the Microsoft Drivers for PHP for SQL Server PHP 7** + +The Microsoft Drivers for PHP for SQL Server are PHP extensions that allow for the reading and writing of SQL Server data from within PHP scripts. The SQLSRV extension provides a procedural interface while the PDO_SQLSRV extension implements PDO for accessing data in all editions of SQL Server 2008 R2 and later (including Azure SQL DB). These drivers rely on the Microsoft ODBC Driver for SQL Server to handle the low-level communication with SQL Server. + +This release contains the SQLSRV and PDO_SQLSRV drivers for PHP 7 with improvements on both drivers and some limitations (see Limitations below for details). Upcoming release(s) will contain more functionality, bug fixes, and more (see Plans below for more details). + +SQL Server Team + + +## Take our survey + +Thank you for taking time to take our February survey. Let us know how we are doing and how you use PHP by taking our March pulse survey: + + + +### Status of Most Recent Builds +| AppVeyor (Windows) |Travis CI (Linux) | Coverage Status +|-------------------------|--------------------------| ------------------ +| [![av-image][]][av-site]| [![tv-image][]][tv-site] |[![Coverage Status][]][coveralls-site] + +[av-image]: https://ci.appveyor.com/api/projects/status/github/Microsoft/msphpsql?branch=dev&svg=true +[av-site]: https://ci.appveyor.com/project/Microsoft-PHPSQL/msphpsql +[tv-image]: https://travis-ci.org/Microsoft/msphpsql.svg?branch=dev +[tv-site]: https://travis-ci.org/Microsoft/msphpsql/ +[Coverage Status]: https://coveralls.io/repos/github/Microsoft/msphpsql/badge.svg?branch=dev +[coveralls-site]: https://coveralls.io/github/Microsoft/msphpsql?branch=dev + +## Get Started + +* [**Ubuntu + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu) +* [**RedHat + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel) +* [**Windows + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows) +* [**Docker**](https://hub.docker.com/r/lbosqmsft/mssql-php-msphpsql/) + + +## Announcements + + Please visit the [blog][blog] for more announcements. + + +## Build (Windows) + +Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Azure/msphpsql/releases) + +#### Prerequisites + +You must first be able to build PHP 7 without including these extensions. For help with doing this, see the [official PHP website][phpbuild] for building your own PHP on Windows. + +#### Compile the drivers + +1. Copy the sqlsrv and/or pdo_sqlsrv source code directory from this repository into the ext subdirectory. + +2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. + +3. Run `configure.bat --with-odbcver=0x0380 and the desired driver options (as below) [plus other options such as --disable-zts for the Non Thread Safe build]` to generate the makefile. You can run `configure.bat --help` to see what other options are available. + * For SQLSRV use: `--enable-sqlsrv=shared` + * For PDO_SQLSRV use: `--enable-pdo=shared --with-pdo-sqlsrv=shared` + +4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. + +5. To install the resulting build, run `nmake install` or just copy php_sqlsrv.dll and/or php_pdo_sqlsrv.dll to your PHP extension directory. + +This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. + +## Install (Windows) + +#### Prerequisites + +- A Web server such as Internet Information Services (IIS) is required. Your Web server must be configured to run PHP +- [Microsoft ODBC Driver 11][odbc11] or [Microsoft ODBC Driver 13][odbc13] + +#### Enable the drivers + +1. Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install). + +2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"` + +3. Restart the Web server. + +## Install (UNIX) +The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7, Debian 8, and Mac OS X. + +### Step 1: Install PHP7+ + +#### PHP 7.0 + +**Ubuntu 15.04, Ubuntu 15.10** + + sudo su + sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' + apt-get update + apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml + +**Ubuntu 16.04** + + sudo su + apt-get update + apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml + +**RedHat 7** + + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php70 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + curl https://www.dotdeb.org/dotdeb.gpg | apt-key add - + echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + apt-get update + apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml + +**Mac OS X** + + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php70 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + +#### PHP 7.1 + +**Ubuntu 16.04** + + sudo su + add-apt-repository ppa:ondrej/php + apt-get update + apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml + +**RedHat 7** + + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php71 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg + echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list + apt-get update + apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml + +**Mac OS X** + + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php71 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + + +### Step 2: Install Prerequisites + +**Ubuntu 15.10** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**Ubuntu 16.04** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**RedHat 7** + + sudo su + curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo + exit + sudo yum update + sudo yum remove unixODBC-utf16-devel #to avoid conflicts + sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools + sudo yum install unixODBC-devel + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**Debian 8** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list + apt-get install -y locales + echo "en_US.UTF-8 UTF-8" > /etc/locale.gen + locale-gen + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql + sudo apt-get install unixodbc-dev + +**Mac OS X** + + brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release + brew update + brew install msodbcsql + brew install mssql-tools + brew install autoconf + +*Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. + +### Step 3: Install the Microsoft PHP Drivers for SQL Server + +*Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. + +On Ubuntu and Debian systems only, run: + + sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system + +On all systems, run: + + sudo pecl install sqlsrv + sudo pecl install pdo_sqlsrv + +### Step 4: Install and Configure Apache + +#### PHP 7.0 + +**Ubuntu and Debian** + + sudo su + apt-get install libapache2-mod-php7.0 apache2 + a2dismod mpm_event + a2enmod mpm_prefork + a2enmod php7.0 + echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini + +**RedHat** + + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini + +**Mac OS X** + + (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf + +#### PHP 7.1 + +**Ubuntu and Debian** + + sudo su + apt-get install libapache2-mod-php7.1 apache2 + a2dismod mpm_event + a2enmod mpm_prefork + a2enmod php7.1 + echo "extension=sqlsrv.so" >> /etc/php/7.1/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php/7.1/apache2/php.ini + +**RedHat** + + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini + +**Mac OS X** + + (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf + + +### Step 5: Restart Apache to load the new php.ini file + +**Ubuntu and Debian** + + sudo service apache2 restart + +**RedHat** + + sudo apachectl restart + +**Mac OS X** + + sudo apachectl restart + +*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` + +### Step 6: Create your sample app +Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into testsql.php and change the servername, username, password and databasename. + + "yourDatabase", + "Uid" => "yourUsername", + "PWD" => "yourPassword" + ); + //Establishes the connection + $conn = sqlsrv_connect( $serverName, $connectionOptions ); + if( $conn === false ) { + die( FormatErrors( sqlsrv_errors())); + } + //Select Query + $tsql= "SELECT @@Version as SQL_VERSION"; + //Executes the query + $getResults= sqlsrv_query( $conn, $tsql ); + //Error handling + + if ( $getResults == FALSE ) + die( FormatErrors( sqlsrv_errors())); + ?> +

Results :

+ "); + } + sqlsrv_free_stmt( $getResults ); + function FormatErrors( $errors ) + { + /* Display errors. */ + echo "Error information:
"; + + foreach ( $errors as $error ) + { + echo "SQLSTATE: ".$error['SQLSTATE']."
"; + echo "Code: ".$error['code']."
"; + echo "Message: ".$error['message']."
"; + } + } + ?> + +### Step 7: Run your sample app + +Go to your browser and type in http://localhost/testsql.php (http://localhost:8080/testsql.php on Mac) +You should be able to connect to your SQL Server/Azure SQL Database. + +The drivers are distributed as shared binary extensions for PHP. They are available in thread safe (*_ts.so) and-non thread safe (*_nts.so) versions. The source code for the drivers is also available, and you can choose whether to compile them as thread safe or non-thread safe versions. The thread safety configuration of your web server will determine which version you need. + +## Sample Code +For samples, please see the sample folder. For setup instructions, see [here](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-php-simple). + +## Limitations + +- This release contains the PHP 7 port of the SQLSRV and PDO_SQLSRV drivers, and does not provide backwards compatibility with PHP 5. +- Binding output parameters using emulate prepare is not supported. +- Linux + - ODBC 3.52 is supported but not 3.8. + - Connection using named instances using '\' is not supported. + - Local encodings other than UTF-8 are not supported, and SQLSRV_ENC_CHAR only supports ASCII characters with ASCII code of 0 to 127. + +## Known Issues +- User defined data types and SQL_VARIANT. +- Binary column binding with emulate prepare ([issue#140](https://github.com/Microsoft/msphpsql/issues/140) ) +- Linux + - The following features are not supported with connection pooling: + - PDO is only supported with unixODBC 2.3.1. + - Unicode connection strings + - sqlsrv_server_info and sqlsrv_client_info return false + - In certain scenarios a generic error message maybe returned instead of a specific error when pooling is disabled + - When retrieving data from columns with a data type of XML, varchar(max), nvarchar(max), or varbinary(max) no data maybe returned or the data maybe truncated depending on the length of the data in the source table. + +## Version number +Version number of PHP drivers follow the [semantic versioning](http://semver.org/): + +Given a version number MAJOR.MINOR.PATCH, + + - MAJOR version is incremented when an incompatible API changes is made, + - MINOR version is incremented when a functionality in a backwards-compatible manner is added, and + - PATCH version is incremented when backwards-compatible bug fixes are made. + +version number MAY have trailing pre-release version to indicate the stability, and/or build meta data. + +- Pre-release version is denoted by hyphen followed by `preview` or `rc` keyword and may be followed by a series of dot separated identifiers. Production quality releases do not contain the pre-release version. `preview` has lower precedence than `rc`. Example of precedence: *preview < preview.1 < rc < rc.1*. +*Note that PECL package version does not have the hyphen before pre-release version, due to restrictions in PECL. Example of PECL package version: 1.2.3preview* +- Build metadata MAY be denoted by a plus sign followed by 4 digits, such as `1.2.3-preview+5678` or `1.2.3+5678`. Build meta data does NOT figure into the precedence order. + + + +## Future Plans +- Expand SQL 16 Feature Support (example: Always Encrypted). +- Add More Verification/Fundamental Tests. +- Bug Fixes. + +## Guidelines for Reporting Issues +We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you: + +- Report each issue as a new issue (but check first if it's already been reported) +- Try to be detailed in your report. Useful information for good bug reports include: + * What you are seeing and what the expected behaviour is + * Can you connect to SQL Server via `sqlcmd`? + * Which driver: SQLSRV or PDO_SQLSRV? + * Environment details: e.g. PHP version, thread safe (TS) or non-thread safe (NTS), 32-bit &/or 64-bit? + * Table schema (for some issues the data types make a big difference!) + * Any other relevant information you want to share +- Try to include a PHP script demonstrating the isolated problem. + +Thank you! + +## FAQs +**Q:** Can we get dates for any of the Future Plans listed above? + +**A:** At this time, Microsoft is not able to announce dates. We are working extremely hard to release future versions of the driver. We will share future plans as appropriate. + +**Q:** What's next? + +**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing previews of upcoming releases frequently. + +**Q:** Is Microsoft taking pull requests for this project? + +**A:** Yes. Please submit pull requests to the **dev** branch and not the **master** branch. + + + +## License + +The Microsoft Drivers for PHP for SQL Server are licensed under the MIT license. See the LICENSE file for more details. + +## Code of conduct + +This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. + +## Resources + +**Documentation**: [MSDN Online Documentation][phpdoc]. + +**Team Blog**: Browse our blog for comments and announcements from the team in the [team blog][blog]. + +**Known Issues**: Please visit the [project on Github][project] to view outstanding [issues][issues] and report new ones. + +[blog]: http://blogs.msdn.com/b/sqlphp/ + +[project]: https://github.com/Azure/msphpsql + +[issues]: https://github.com/Azure/msphpsql/issues + +[phpweb]: http://php.net + +[phpbuild]: https://wiki.php.net/internals/windows/stepbystepbuild + +[phpdoc]: http://msdn.microsoft.com/library/dd903047%28SQL.11%29.aspx + +[odbc11]: https://www.microsoft.com/download/details.aspx?id=36434 + +[odbc13]: https://www.microsoft.com/download/details.aspx?id=50420 + +[odbcLinux]: https://msdn.microsoft.com/library/hh568454(v=sql.110).aspx + +[phpazure]: https://azure.microsoft.com/documentation/articles/sql-database-develop-php-simple-windows/ + +[PHPMan]: http://php.net/manual/install.unix.php + +[LinuxDM]: https://msdn.microsoft.com/library/hh568449(v=sql.110).aspx + +[httpd_source]: http://httpd.apache.org/ + +[apr_source]: http://apr.apache.org/ + +[httpdconf]: http://php.net/manual/en/install.unix.apache2.php + +[ODBCinstallers]: https://blogs.msdn.microsoft.com/sqlnativeclient/2016/09/06/preview-release-of-the-sql-server-cc-odbc-driver-13-0-0-for-linux From 77522875fd325d828303f895c63d5d5edc9905fd Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Thu, 13 Jul 2017 15:10:19 -0700 Subject: [PATCH 6/8] A few more changes --- README.md | 174 +++++++++++++++++++++++++++--------------------------- 1 file changed, 88 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index f59f8bdd..bf8395c4 100644 --- a/README.md +++ b/README.md @@ -86,29 +86,29 @@ The following instructions assume a clean environment and show how to install PH #### PHP 7.0 -**Ubuntu 15.04, Ubuntu 15.10** +**Ubuntu 15.10** - sudo su - sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' - apt-get update - apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml + sudo su + sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' + apt-get update + apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml **Ubuntu 16.04** - sudo su - apt-get update - apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml + sudo su + apt-get update + apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml **RedHat 7** - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php70 - yum update - yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php70 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc **Debian 8** @@ -122,35 +122,37 @@ The following instructions assume a clean environment and show how to install PH **Mac OS X** - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php70 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php70 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile #### PHP 7.1 +Note that there are no PHP 7.1 packages available for Ubuntu 15.10. + **Ubuntu 16.04** - sudo su - add-apt-repository ppa:ondrej/php - apt-get update - apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml + sudo su + add-apt-repository ppa:ondrej/php + apt-get update + apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml **RedHat 7** - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php71 - yum update - yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php71 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc **Debian 8** @@ -163,57 +165,57 @@ The following instructions assume a clean environment and show how to install PH **Mac OS X** - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php71 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php71 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile ### Step 2: Install Prerequisites **Ubuntu 15.10** - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc **Ubuntu 16.04** - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc **RedHat 7** - sudo su - curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo - exit - sudo yum update - sudo yum remove unixODBC-utf16-devel #to avoid conflicts - sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools - sudo yum install unixODBC-devel - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc + sudo su + curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo + exit + sudo yum update + sudo yum remove unixODBC-utf16-devel #to avoid conflicts + sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools + sudo yum install unixODBC-devel + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc **Debian 8** @@ -230,11 +232,11 @@ The following instructions assume a clean environment and show how to install PH **Mac OS X** - brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release - brew update - brew install msodbcsql - brew install mssql-tools - brew install autoconf + brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release + brew update + brew install msodbcsql + brew install mssql-tools + brew install autoconf *Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. @@ -299,20 +301,20 @@ On all systems, run: (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf - + ### Step 5: Restart Apache to load the new php.ini file **Ubuntu and Debian** - sudo service apache2 restart + sudo service apache2 restart **RedHat** - sudo apachectl restart + sudo apachectl restart **Mac OS X** - sudo apachectl restart + sudo apachectl restart *Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` @@ -406,7 +408,7 @@ version number MAY have trailing pre-release version to indicate the stability, *Note that PECL package version does not have the hyphen before pre-release version, due to restrictions in PECL. Example of PECL package version: 1.2.3preview* - Build metadata MAY be denoted by a plus sign followed by 4 digits, such as `1.2.3-preview+5678` or `1.2.3+5678`. Build meta data does NOT figure into the precedence order. - + ## Future Plans - Expand SQL 16 Feature Support (example: Always Encrypted). From a947aec0da2112c611f2c2f13262b11ae4b06444 Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Mon, 17 Jul 2017 14:07:22 -0700 Subject: [PATCH 7/8] Minor tweaks per review comments --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf8395c4..a6d7c379 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Thank you for taking time to take our February survey. Let us know how we are do ## Build (Windows) -Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Azure/msphpsql/releases) +Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Microsoft/msphpsql/releases) #### Prerequisites @@ -75,7 +75,7 @@ This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the 1. Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install). -2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"` +2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"`. Note that the precompiled binaries have different names -- substitute accordingly in php.ini. 3. Restart the Web server. From 6eb1e0311fd5f8f2c6bd24d6727956f595ba12ad Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 1 Aug 2017 16:09:56 -0700 Subject: [PATCH 8/8] Fixed line endings --- README.md | 988 +++++++++++++++++++++++++++--------------------------- 1 file changed, 494 insertions(+), 494 deletions(-) diff --git a/README.md b/README.md index a6d7c379..302e65c0 100644 --- a/README.md +++ b/README.md @@ -1,494 +1,494 @@ -# Microsoft Drivers for PHP for SQL Server - -**Welcome to the Microsoft Drivers for PHP for SQL Server PHP 7** - -The Microsoft Drivers for PHP for SQL Server are PHP extensions that allow for the reading and writing of SQL Server data from within PHP scripts. The SQLSRV extension provides a procedural interface while the PDO_SQLSRV extension implements PDO for accessing data in all editions of SQL Server 2008 R2 and later (including Azure SQL DB). These drivers rely on the Microsoft ODBC Driver for SQL Server to handle the low-level communication with SQL Server. - -This release contains the SQLSRV and PDO_SQLSRV drivers for PHP 7 with improvements on both drivers and some limitations (see Limitations below for details). Upcoming release(s) will contain more functionality, bug fixes, and more (see Plans below for more details). - -SQL Server Team - - -## Take our survey - -Thank you for taking time to take our February survey. Let us know how we are doing and how you use PHP by taking our March pulse survey: - - - -### Status of Most Recent Builds -| AppVeyor (Windows) |Travis CI (Linux) | Coverage Status -|-------------------------|--------------------------| ------------------ -| [![av-image][]][av-site]| [![tv-image][]][tv-site] |[![Coverage Status][]][coveralls-site] - -[av-image]: https://ci.appveyor.com/api/projects/status/github/Microsoft/msphpsql?branch=dev&svg=true -[av-site]: https://ci.appveyor.com/project/Microsoft-PHPSQL/msphpsql -[tv-image]: https://travis-ci.org/Microsoft/msphpsql.svg?branch=dev -[tv-site]: https://travis-ci.org/Microsoft/msphpsql/ -[Coverage Status]: https://coveralls.io/repos/github/Microsoft/msphpsql/badge.svg?branch=dev -[coveralls-site]: https://coveralls.io/github/Microsoft/msphpsql?branch=dev - -## Get Started - -* [**Ubuntu + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu) -* [**RedHat + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel) -* [**Windows + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows) -* [**Docker**](https://hub.docker.com/r/lbosqmsft/mssql-php-msphpsql/) - - -## Announcements - - Please visit the [blog][blog] for more announcements. - - -## Build (Windows) - -Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Microsoft/msphpsql/releases) - -#### Prerequisites - -You must first be able to build PHP 7 without including these extensions. For help with doing this, see the [official PHP website][phpbuild] for building your own PHP on Windows. - -#### Compile the drivers - -1. Copy the sqlsrv and/or pdo_sqlsrv source code directory from this repository into the ext subdirectory. - -2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. - -3. Run `configure.bat --with-odbcver=0x0380 and the desired driver options (as below) [plus other options such as --disable-zts for the Non Thread Safe build]` to generate the makefile. You can run `configure.bat --help` to see what other options are available. - * For SQLSRV use: `--enable-sqlsrv=shared` - * For PDO_SQLSRV use: `--enable-pdo=shared --with-pdo-sqlsrv=shared` - -4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. - -5. To install the resulting build, run `nmake install` or just copy php_sqlsrv.dll and/or php_pdo_sqlsrv.dll to your PHP extension directory. - -This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. - -## Install (Windows) - -#### Prerequisites - -- A Web server such as Internet Information Services (IIS) is required. Your Web server must be configured to run PHP -- [Microsoft ODBC Driver 11][odbc11] or [Microsoft ODBC Driver 13][odbc13] - -#### Enable the drivers - -1. Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install). - -2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"`. Note that the precompiled binaries have different names -- substitute accordingly in php.ini. - -3. Restart the Web server. - -## Install (UNIX) -The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7, Debian 8, and Mac OS X. - -### Step 1: Install PHP7+ - -#### PHP 7.0 - -**Ubuntu 15.10** - - sudo su - sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' - apt-get update - apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml - -**Ubuntu 16.04** - - sudo su - apt-get update - apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml - -**RedHat 7** - - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php70 - yum update - yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc - -**Debian 8** - - sudo su - apt-get install curl apt-transport-https - curl https://www.dotdeb.org/dotdeb.gpg | apt-key add - - echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list - echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list - apt-get update - apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml - -**Mac OS X** - - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php70 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile - -#### PHP 7.1 - -Note that there are no PHP 7.1 packages available for Ubuntu 15.10. - -**Ubuntu 16.04** - - sudo su - add-apt-repository ppa:ondrej/php - apt-get update - apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml - -**RedHat 7** - - sudo su - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm - wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm - rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm - subscription-manager repos --enable=rhel-7-server-optional-rpms - yum-config-manager --enable remi-php71 - yum update - yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc - -**Debian 8** - - sudo su - apt-get install curl apt-transport-https - wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg - echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list - apt-get update - apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml - -**Mac OS X** - - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap - brew tap homebrew/dupes - brew tap homebrew/versions - brew tap homebrew/homebrew-php - brew install php71 --with-pear --with-httpd24 --with-cgi - echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile - echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile - source ~/.bash_profile - - -### Step 2: Install Prerequisites - -**Ubuntu 15.10** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**Ubuntu 16.04** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools - sudo apt-get install unixodbc-dev - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**RedHat 7** - - sudo su - curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo - exit - sudo yum update - sudo yum remove unixODBC-utf16-devel #to avoid conflicts - sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools - sudo yum install unixODBC-devel - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile - echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc - source ~/.bashrc - -**Debian 8** - - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list - apt-get install -y locales - echo "en_US.UTF-8 UTF-8" > /etc/locale.gen - locale-gen - exit - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install msodbcsql - sudo apt-get install unixodbc-dev - -**Mac OS X** - - brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release - brew update - brew install msodbcsql - brew install mssql-tools - brew install autoconf - -*Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. - -### Step 3: Install the Microsoft PHP Drivers for SQL Server - -*Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. - -On Ubuntu and Debian systems only, run: - - sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system - -On all systems, run: - - sudo pecl install sqlsrv - sudo pecl install pdo_sqlsrv - -### Step 4: Install and Configure Apache - -#### PHP 7.0 - -**Ubuntu and Debian** - - sudo su - apt-get install libapache2-mod-php7.0 apache2 - a2dismod mpm_event - a2enmod mpm_prefork - a2enmod php7.0 - echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini - echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini - -**RedHat** - - sudo su - yum install httpd - echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini - echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini - -**Mac OS X** - - (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf - -#### PHP 7.1 - -**Ubuntu and Debian** - - sudo su - apt-get install libapache2-mod-php7.1 apache2 - a2dismod mpm_event - a2enmod mpm_prefork - a2enmod php7.1 - echo "extension=sqlsrv.so" >> /etc/php/7.1/apache2/php.ini - echo "extension=pdo_sqlsrv.so" >> /etc/php/7.1/apache2/php.ini - -**RedHat** - - sudo su - yum install httpd - echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini - echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini - -**Mac OS X** - - (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf - - -### Step 5: Restart Apache to load the new php.ini file - -**Ubuntu and Debian** - - sudo service apache2 restart - -**RedHat** - - sudo apachectl restart - -**Mac OS X** - - sudo apachectl restart - -*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` - -### Step 6: Create your sample app -Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into testsql.php and change the servername, username, password and databasename. - - "yourDatabase", - "Uid" => "yourUsername", - "PWD" => "yourPassword" - ); - //Establishes the connection - $conn = sqlsrv_connect( $serverName, $connectionOptions ); - if( $conn === false ) { - die( FormatErrors( sqlsrv_errors())); - } - //Select Query - $tsql= "SELECT @@Version as SQL_VERSION"; - //Executes the query - $getResults= sqlsrv_query( $conn, $tsql ); - //Error handling - - if ( $getResults == FALSE ) - die( FormatErrors( sqlsrv_errors())); - ?> -

Results :

- "); - } - sqlsrv_free_stmt( $getResults ); - function FormatErrors( $errors ) - { - /* Display errors. */ - echo "Error information:
"; - - foreach ( $errors as $error ) - { - echo "SQLSTATE: ".$error['SQLSTATE']."
"; - echo "Code: ".$error['code']."
"; - echo "Message: ".$error['message']."
"; - } - } - ?> - -### Step 7: Run your sample app - -Go to your browser and type in http://localhost/testsql.php (http://localhost:8080/testsql.php on Mac) -You should be able to connect to your SQL Server/Azure SQL Database. - -The drivers are distributed as shared binary extensions for PHP. They are available in thread safe (*_ts.so) and-non thread safe (*_nts.so) versions. The source code for the drivers is also available, and you can choose whether to compile them as thread safe or non-thread safe versions. The thread safety configuration of your web server will determine which version you need. - -## Sample Code -For samples, please see the sample folder. For setup instructions, see [here](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-php-simple). - -## Limitations - -- This release contains the PHP 7 port of the SQLSRV and PDO_SQLSRV drivers, and does not provide backwards compatibility with PHP 5. -- Binding output parameters using emulate prepare is not supported. -- Linux - - ODBC 3.52 is supported but not 3.8. - - Connection using named instances using '\' is not supported. - - Local encodings other than UTF-8 are not supported, and SQLSRV_ENC_CHAR only supports ASCII characters with ASCII code of 0 to 127. - -## Known Issues -- User defined data types and SQL_VARIANT. -- Binary column binding with emulate prepare ([issue#140](https://github.com/Microsoft/msphpsql/issues/140) ) -- Linux - - The following features are not supported with connection pooling: - - PDO is only supported with unixODBC 2.3.1. - - Unicode connection strings - - sqlsrv_server_info and sqlsrv_client_info return false - - In certain scenarios a generic error message maybe returned instead of a specific error when pooling is disabled - - When retrieving data from columns with a data type of XML, varchar(max), nvarchar(max), or varbinary(max) no data maybe returned or the data maybe truncated depending on the length of the data in the source table. - -## Version number -Version number of PHP drivers follow the [semantic versioning](http://semver.org/): - -Given a version number MAJOR.MINOR.PATCH, - - - MAJOR version is incremented when an incompatible API changes is made, - - MINOR version is incremented when a functionality in a backwards-compatible manner is added, and - - PATCH version is incremented when backwards-compatible bug fixes are made. - -version number MAY have trailing pre-release version to indicate the stability, and/or build meta data. - -- Pre-release version is denoted by hyphen followed by `preview` or `rc` keyword and may be followed by a series of dot separated identifiers. Production quality releases do not contain the pre-release version. `preview` has lower precedence than `rc`. Example of precedence: *preview < preview.1 < rc < rc.1*. -*Note that PECL package version does not have the hyphen before pre-release version, due to restrictions in PECL. Example of PECL package version: 1.2.3preview* -- Build metadata MAY be denoted by a plus sign followed by 4 digits, such as `1.2.3-preview+5678` or `1.2.3+5678`. Build meta data does NOT figure into the precedence order. - - - -## Future Plans -- Expand SQL 16 Feature Support (example: Always Encrypted). -- Add More Verification/Fundamental Tests. -- Bug Fixes. - -## Guidelines for Reporting Issues -We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you: - -- Report each issue as a new issue (but check first if it's already been reported) -- Try to be detailed in your report. Useful information for good bug reports include: - * What you are seeing and what the expected behaviour is - * Can you connect to SQL Server via `sqlcmd`? - * Which driver: SQLSRV or PDO_SQLSRV? - * Environment details: e.g. PHP version, thread safe (TS) or non-thread safe (NTS), 32-bit &/or 64-bit? - * Table schema (for some issues the data types make a big difference!) - * Any other relevant information you want to share -- Try to include a PHP script demonstrating the isolated problem. - -Thank you! - -## FAQs -**Q:** Can we get dates for any of the Future Plans listed above? - -**A:** At this time, Microsoft is not able to announce dates. We are working extremely hard to release future versions of the driver. We will share future plans as appropriate. - -**Q:** What's next? - -**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing previews of upcoming releases frequently. - -**Q:** Is Microsoft taking pull requests for this project? - -**A:** Yes. Please submit pull requests to the **dev** branch and not the **master** branch. - - - -## License - -The Microsoft Drivers for PHP for SQL Server are licensed under the MIT license. See the LICENSE file for more details. - -## Code of conduct - -This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. - -## Resources - -**Documentation**: [MSDN Online Documentation][phpdoc]. - -**Team Blog**: Browse our blog for comments and announcements from the team in the [team blog][blog]. - -**Known Issues**: Please visit the [project on Github][project] to view outstanding [issues][issues] and report new ones. - -[blog]: http://blogs.msdn.com/b/sqlphp/ - -[project]: https://github.com/Azure/msphpsql - -[issues]: https://github.com/Azure/msphpsql/issues - -[phpweb]: http://php.net - -[phpbuild]: https://wiki.php.net/internals/windows/stepbystepbuild - -[phpdoc]: http://msdn.microsoft.com/library/dd903047%28SQL.11%29.aspx - -[odbc11]: https://www.microsoft.com/download/details.aspx?id=36434 - -[odbc13]: https://www.microsoft.com/download/details.aspx?id=50420 - -[odbcLinux]: https://msdn.microsoft.com/library/hh568454(v=sql.110).aspx - -[phpazure]: https://azure.microsoft.com/documentation/articles/sql-database-develop-php-simple-windows/ - -[PHPMan]: http://php.net/manual/install.unix.php - -[LinuxDM]: https://msdn.microsoft.com/library/hh568449(v=sql.110).aspx - -[httpd_source]: http://httpd.apache.org/ - -[apr_source]: http://apr.apache.org/ - -[httpdconf]: http://php.net/manual/en/install.unix.apache2.php - -[ODBCinstallers]: https://blogs.msdn.microsoft.com/sqlnativeclient/2016/09/06/preview-release-of-the-sql-server-cc-odbc-driver-13-0-0-for-linux +# Microsoft Drivers for PHP for SQL Server + +**Welcome to the Microsoft Drivers for PHP for SQL Server PHP 7** + +The Microsoft Drivers for PHP for SQL Server are PHP extensions that allow for the reading and writing of SQL Server data from within PHP scripts. The SQLSRV extension provides a procedural interface while the PDO_SQLSRV extension implements PDO for accessing data in all editions of SQL Server 2008 R2 and later (including Azure SQL DB). These drivers rely on the Microsoft ODBC Driver for SQL Server to handle the low-level communication with SQL Server. + +This release contains the SQLSRV and PDO_SQLSRV drivers for PHP 7 with improvements on both drivers and some limitations (see Limitations below for details). Upcoming release(s) will contain more functionality, bug fixes, and more (see Plans below for more details). + +SQL Server Team + + +## Take our survey + +Thank you for taking time to take our February survey. Let us know how we are doing and how you use PHP by taking our March pulse survey: + + + +### Status of Most Recent Builds +| AppVeyor (Windows) |Travis CI (Linux) | Coverage Status +|-------------------------|--------------------------| ------------------ +| [![av-image][]][av-site]| [![tv-image][]][tv-site] |[![Coverage Status][]][coveralls-site] + +[av-image]: https://ci.appveyor.com/api/projects/status/github/Microsoft/msphpsql?branch=dev&svg=true +[av-site]: https://ci.appveyor.com/project/Microsoft-PHPSQL/msphpsql +[tv-image]: https://travis-ci.org/Microsoft/msphpsql.svg?branch=dev +[tv-site]: https://travis-ci.org/Microsoft/msphpsql/ +[Coverage Status]: https://coveralls.io/repos/github/Microsoft/msphpsql/badge.svg?branch=dev +[coveralls-site]: https://coveralls.io/github/Microsoft/msphpsql?branch=dev + +## Get Started + +* [**Ubuntu + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu) +* [**RedHat + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel) +* [**Windows + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows) +* [**Docker**](https://hub.docker.com/r/lbosqmsft/mssql-php-msphpsql/) + + +## Announcements + + Please visit the [blog][blog] for more announcements. + + +## Build (Windows) + +Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Microsoft/msphpsql/releases) + +#### Prerequisites + +You must first be able to build PHP 7 without including these extensions. For help with doing this, see the [official PHP website][phpbuild] for building your own PHP on Windows. + +#### Compile the drivers + +1. Copy the sqlsrv and/or pdo_sqlsrv source code directory from this repository into the ext subdirectory. + +2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. + +3. Run `configure.bat --with-odbcver=0x0380 and the desired driver options (as below) [plus other options such as --disable-zts for the Non Thread Safe build]` to generate the makefile. You can run `configure.bat --help` to see what other options are available. + * For SQLSRV use: `--enable-sqlsrv=shared` + * For PDO_SQLSRV use: `--enable-pdo=shared --with-pdo-sqlsrv=shared` + +4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. + +5. To install the resulting build, run `nmake install` or just copy php_sqlsrv.dll and/or php_pdo_sqlsrv.dll to your PHP extension directory. + +This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. + +## Install (Windows) + +#### Prerequisites + +- A Web server such as Internet Information Services (IIS) is required. Your Web server must be configured to run PHP +- [Microsoft ODBC Driver 11][odbc11] or [Microsoft ODBC Driver 13][odbc13] + +#### Enable the drivers + +1. Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install). + +2. Enable it within your PHP installation's php.ini: `extension=php_sqlsrv.dll` and/or `extension=php_pdo_sqlsrv.dll`. If necessary, specify the extension directory using extension_dir, for example: `extension_dir = "C:\PHP\ext"`. Note that the precompiled binaries have different names -- substitute accordingly in php.ini. + +3. Restart the Web server. + +## Install (UNIX) +The following instructions assume a clean environment and show how to install PHP 7.x, Microsoft ODBC driver, apache, and Microsoft PHP drivers on Ubuntu 15, 16, RedHat 7, Debian 8, and Mac OS X. + +### Step 1: Install PHP7+ + +#### PHP 7.0 + +**Ubuntu 15.10** + + sudo su + sh -c 'echo "deb http://packages.dotdeb.org jessie all \ndeb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list' + apt-get update + apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml + +**Ubuntu 16.04** + + sudo su + apt-get update + apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev php7.0-xml + +**RedHat 7** + + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php70 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + curl https://www.dotdeb.org/dotdeb.gpg | apt-key add - + echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list + apt-get update + apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml + +**Mac OS X** + + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php70 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + +#### PHP 7.1 + +Note that there are no PHP 7.1 packages available for Ubuntu 15.10. + +**Ubuntu 16.04** + + sudo su + add-apt-repository ppa:ondrej/php + apt-get update + apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev php7.1-xml + +**RedHat 7** + + sudo su + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm + rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm + subscription-manager repos --enable=rhel-7-server-optional-rpms + yum-config-manager --enable remi-php71 + yum update + yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc + +**Debian 8** + + sudo su + apt-get install curl apt-transport-https + wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg + echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list + apt-get update + apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml + +**Mac OS X** + + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + brew tap + brew tap homebrew/dupes + brew tap homebrew/versions + brew tap homebrew/homebrew-php + brew install php71 --with-pear --with-httpd24 --with-cgi + echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile + echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + + +### Step 2: Install Prerequisites + +**Ubuntu 15.10** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/15.10/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**Ubuntu 16.04** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools + sudo apt-get install unixodbc-dev + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**RedHat 7** + + sudo su + curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo + exit + sudo yum update + sudo yum remove unixODBC-utf16-devel #to avoid conflicts + sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools + sudo yum install unixODBC-devel + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**Debian 8** + + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list + apt-get install -y locales + echo "en_US.UTF-8 UTF-8" > /etc/locale.gen + locale-gen + exit + sudo apt-get update + sudo ACCEPT_EULA=Y apt-get install msodbcsql + sudo apt-get install unixodbc-dev + +**Mac OS X** + + brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release + brew update + brew install msodbcsql + brew install mssql-tools + brew install autoconf + +*Note: Be sure to install PHP 7+ before proceeding to step 3. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+. + +### Step 3: Install the Microsoft PHP Drivers for SQL Server + +*Note: You can run `sudo pecl search sqlsrv` to search for the latest releases and `sudo pecl install sqlsrv-[version]` to install a specific version. PECL installs the stable version when version is not specified. Drivers are Mac-compatible starting from `4.1.7preview` release. + +On Ubuntu and Debian systems only, run: + + sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system + +On all systems, run: + + sudo pecl install sqlsrv + sudo pecl install pdo_sqlsrv + +### Step 4: Install and Configure Apache + +#### PHP 7.0 + +**Ubuntu and Debian** + + sudo su + apt-get install libapache2-mod-php7.0 apache2 + a2dismod mpm_event + a2enmod mpm_prefork + a2enmod php7.0 + echo "extension=sqlsrv.so" >> /etc/php/7.0/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini + +**RedHat** + + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini + +**Mac OS X** + + (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf + +#### PHP 7.1 + +**Ubuntu and Debian** + + sudo su + apt-get install libapache2-mod-php7.1 apache2 + a2dismod mpm_event + a2enmod mpm_prefork + a2enmod php7.1 + echo "extension=sqlsrv.so" >> /etc/php/7.1/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php/7.1/apache2/php.ini + +**RedHat** + + sudo su + yum install httpd + echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini + echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini + +**Mac OS X** + + (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf + + +### Step 5: Restart Apache to load the new php.ini file + +**Ubuntu and Debian** + + sudo service apache2 restart + +**RedHat** + + sudo apachectl restart + +**Mac OS X** + + sudo apachectl restart + +*Note to RedHat users: SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to database through SELinux, run `sudo setsebool -P httpd_can_network_connect_db 1` + +### Step 6: Create your sample app +Navigate to `/var/www/html` (`/usr/local/var/www/htdocs` on Mac) and create a new file called testsql.php. Copy and paste the following code into testsql.php and change the servername, username, password and databasename. + + "yourDatabase", + "Uid" => "yourUsername", + "PWD" => "yourPassword" + ); + //Establishes the connection + $conn = sqlsrv_connect( $serverName, $connectionOptions ); + if( $conn === false ) { + die( FormatErrors( sqlsrv_errors())); + } + //Select Query + $tsql= "SELECT @@Version as SQL_VERSION"; + //Executes the query + $getResults= sqlsrv_query( $conn, $tsql ); + //Error handling + + if ( $getResults == FALSE ) + die( FormatErrors( sqlsrv_errors())); + ?> +

Results :

+ "); + } + sqlsrv_free_stmt( $getResults ); + function FormatErrors( $errors ) + { + /* Display errors. */ + echo "Error information:
"; + + foreach ( $errors as $error ) + { + echo "SQLSTATE: ".$error['SQLSTATE']."
"; + echo "Code: ".$error['code']."
"; + echo "Message: ".$error['message']."
"; + } + } + ?> + +### Step 7: Run your sample app + +Go to your browser and type in http://localhost/testsql.php (http://localhost:8080/testsql.php on Mac) +You should be able to connect to your SQL Server/Azure SQL Database. + +The drivers are distributed as shared binary extensions for PHP. They are available in thread safe (*_ts.so) and-non thread safe (*_nts.so) versions. The source code for the drivers is also available, and you can choose whether to compile them as thread safe or non-thread safe versions. The thread safety configuration of your web server will determine which version you need. + +## Sample Code +For samples, please see the sample folder. For setup instructions, see [here](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-php-simple). + +## Limitations + +- This release contains the PHP 7 port of the SQLSRV and PDO_SQLSRV drivers, and does not provide backwards compatibility with PHP 5. +- Binding output parameters using emulate prepare is not supported. +- Linux + - ODBC 3.52 is supported but not 3.8. + - Connection using named instances using '\' is not supported. + - Local encodings other than UTF-8 are not supported, and SQLSRV_ENC_CHAR only supports ASCII characters with ASCII code of 0 to 127. + +## Known Issues +- User defined data types and SQL_VARIANT. +- Binary column binding with emulate prepare ([issue#140](https://github.com/Microsoft/msphpsql/issues/140) ) +- Linux + - The following features are not supported with connection pooling: + - PDO is only supported with unixODBC 2.3.1. + - Unicode connection strings + - sqlsrv_server_info and sqlsrv_client_info return false + - In certain scenarios a generic error message maybe returned instead of a specific error when pooling is disabled + - When retrieving data from columns with a data type of XML, varchar(max), nvarchar(max), or varbinary(max) no data maybe returned or the data maybe truncated depending on the length of the data in the source table. + +## Version number +Version number of PHP drivers follow the [semantic versioning](http://semver.org/): + +Given a version number MAJOR.MINOR.PATCH, + + - MAJOR version is incremented when an incompatible API changes is made, + - MINOR version is incremented when a functionality in a backwards-compatible manner is added, and + - PATCH version is incremented when backwards-compatible bug fixes are made. + +version number MAY have trailing pre-release version to indicate the stability, and/or build meta data. + +- Pre-release version is denoted by hyphen followed by `preview` or `rc` keyword and may be followed by a series of dot separated identifiers. Production quality releases do not contain the pre-release version. `preview` has lower precedence than `rc`. Example of precedence: *preview < preview.1 < rc < rc.1*. +*Note that PECL package version does not have the hyphen before pre-release version, due to restrictions in PECL. Example of PECL package version: 1.2.3preview* +- Build metadata MAY be denoted by a plus sign followed by 4 digits, such as `1.2.3-preview+5678` or `1.2.3+5678`. Build meta data does NOT figure into the precedence order. + + + +## Future Plans +- Expand SQL 16 Feature Support (example: Always Encrypted). +- Add More Verification/Fundamental Tests. +- Bug Fixes. + +## Guidelines for Reporting Issues +We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you: + +- Report each issue as a new issue (but check first if it's already been reported) +- Try to be detailed in your report. Useful information for good bug reports include: + * What you are seeing and what the expected behaviour is + * Can you connect to SQL Server via `sqlcmd`? + * Which driver: SQLSRV or PDO_SQLSRV? + * Environment details: e.g. PHP version, thread safe (TS) or non-thread safe (NTS), 32-bit &/or 64-bit? + * Table schema (for some issues the data types make a big difference!) + * Any other relevant information you want to share +- Try to include a PHP script demonstrating the isolated problem. + +Thank you! + +## FAQs +**Q:** Can we get dates for any of the Future Plans listed above? + +**A:** At this time, Microsoft is not able to announce dates. We are working extremely hard to release future versions of the driver. We will share future plans as appropriate. + +**Q:** What's next? + +**A:** On July 6, 2017 we released the production release version 4.3.0 of our PHP Driver. We will continue working on our future plans and releasing previews of upcoming releases frequently. + +**Q:** Is Microsoft taking pull requests for this project? + +**A:** Yes. Please submit pull requests to the **dev** branch and not the **master** branch. + + + +## License + +The Microsoft Drivers for PHP for SQL Server are licensed under the MIT license. See the LICENSE file for more details. + +## Code of conduct + +This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. + +## Resources + +**Documentation**: [MSDN Online Documentation][phpdoc]. + +**Team Blog**: Browse our blog for comments and announcements from the team in the [team blog][blog]. + +**Known Issues**: Please visit the [project on Github][project] to view outstanding [issues][issues] and report new ones. + +[blog]: http://blogs.msdn.com/b/sqlphp/ + +[project]: https://github.com/Azure/msphpsql + +[issues]: https://github.com/Azure/msphpsql/issues + +[phpweb]: http://php.net + +[phpbuild]: https://wiki.php.net/internals/windows/stepbystepbuild + +[phpdoc]: http://msdn.microsoft.com/library/dd903047%28SQL.11%29.aspx + +[odbc11]: https://www.microsoft.com/download/details.aspx?id=36434 + +[odbc13]: https://www.microsoft.com/download/details.aspx?id=50420 + +[odbcLinux]: https://msdn.microsoft.com/library/hh568454(v=sql.110).aspx + +[phpazure]: https://azure.microsoft.com/documentation/articles/sql-database-develop-php-simple-windows/ + +[PHPMan]: http://php.net/manual/install.unix.php + +[LinuxDM]: https://msdn.microsoft.com/library/hh568449(v=sql.110).aspx + +[httpd_source]: http://httpd.apache.org/ + +[apr_source]: http://apr.apache.org/ + +[httpdconf]: http://php.net/manual/en/install.unix.apache2.php + +[ODBCinstallers]: https://blogs.msdn.microsoft.com/sqlnativeclient/2016/09/06/preview-release-of-the-sql-server-cc-odbc-driver-13-0-0-for-linux