From 57c83525a3e7deb448fb44ce857423f13bb4138c Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 11 Jul 2017 17:26:02 -0700 Subject: [PATCH 01/87] 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 02/87] 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 03/87] 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 04/87] 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 05/87] 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 06/87] 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 07/87] 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 c5b94e789d6cce0d6419d1ff08ef2a9f50916595 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Thu, 27 Jul 2017 19:12:33 -0700 Subject: [PATCH 08/87] test logs --- .travis.yml | 96 +++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96f02d83..25bb9835 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,47 +1,49 @@ -sudo: required - -os: linux -dist: trusty - -group: edge - -services: - - docker - -env: - global: - - REPORT_EXIT_STATUS=1 - - ACCEPT_EULA=Y - - PHPSQLDIR=/REPO/msphpsql-dev - - TEST_PHP_SQL_SERVER=sql - - SQLSRV_DBNAME=msphpsql_sqlsrv - - PDOSQLSRV_DBNAME=msphpsql_pdosqlsrv - -before_install: - - docker pull microsoft/mssql-server-linux - -install: - - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . - - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12@' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - -script: - - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev - - docker ps -a - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client coveralls -e ./source/shared/ --gcov-options '\-lp' - - docker stop client - - docker ps -a - - -notifications: - email: false - +sudo: required + +os: linux +dist: trusty + +group: edge + +services: + - docker + +env: + global: + - REPORT_EXIT_STATUS=1 + - ACCEPT_EULA=Y + - PHPSQLDIR=/REPO/msphpsql-dev + - TEST_PHP_SQL_SERVER=sql + - SQLSRV_DBNAME=msphpsql_sqlsrv + - PDOSQLSRV_DBNAME=msphpsql_pdosqlsrv + +before_install: + - docker pull microsoft/mssql-server-linux + +install: + - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . + - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12@' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux + +script: + - docker logs sql + - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev + - docker logs client + - docker ps -a + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME + - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt + - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt + - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $SQLSRV_DBNAME + - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $PDOSQLSRV_DBNAME + - docker exec client coveralls -e ./source/shared/ --gcov-options '\-lp' + - docker stop client + - docker ps -a + + +notifications: + email: false + From cb90f9f485360de42cd2f2dfdcb7e0ad56dc4213 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 11:13:35 -0700 Subject: [PATCH 09/87] updated ODBC installers in dockerfile --- Dockerfile-msphpsql | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 81ff073f..6b80ec4b 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -4,25 +4,26 @@ FROM ubuntu:16.04 # Update Ubuntu Software repository RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \ - apt-get -y install \ - apt-transport-https \ - apt-utils \ - autoconf \ - curl \ - g++ \ - gcc \ - git \ - lcov \ - libxml2-dev \ - locales \ - make \ - php7.0 \ - php7.0-dev \ - python-pip \ - re2c \ - unixodbc-dev \ - unzip && apt-get clean - + apt-get -y install \ + apt-transport-https \ + apt-utils \ + autoconf \ + curl \ + g++ \ + gcc \ + git \ + lcov \ + libxml2-dev \ + locales \ + make \ + php7.1 \ + php7.1-dev \ + php7.1-xml \ + python-pip \ + re2c \ + unixodbc-dev \ + unzip && apt-get clean + ARG PHPSQLDIR=/REPO/msphpsql-dev ENV TEST_PHP_SQL_SERVER sql ENV TEST_PHP_SQL_UID sa @@ -36,11 +37,10 @@ ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list -#RUN echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release/ xenial main" > /etc/apt/sources.list.d/mssqlpreview.list -#RUN apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools - -ENV PATH="/opt/mssql-tools/bin:${PATH}" +RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile +RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc +RUN source ~/.bashrc #install coveralls RUN pip install --upgrade pip && pip install cpp-coveralls From 07f3a1782e457f31d0265ed0ec17fa8edc85625b Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 11:18:01 -0700 Subject: [PATCH 10/87] reverted 7.1 to 7.0 ub16 docker failed to find the packages --- Dockerfile-msphpsql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 6b80ec4b..d815a1fc 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -16,9 +16,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \ libxml2-dev \ locales \ make \ - php7.1 \ - php7.1-dev \ - php7.1-xml \ + php7.0 \ + php7.0-dev \ python-pip \ re2c \ unixodbc-dev \ From 6a5bb44bbda451d7d1bc6a8cfc0fab0bebdbce6b Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 12:52:36 -0700 Subject: [PATCH 11/87] added path to bashrc and bash_profile --- Dockerfile-msphpsql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index d815a1fc..94351928 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -37,9 +37,11 @@ RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools +ENV PATH="/opt/mssql-tools/bin:${PATH}" RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc -RUN source ~/.bashrc +RUN /bin/bash -c "source ~/.bashrc" + #install coveralls RUN pip install --upgrade pip && pip install cpp-coveralls From c0139f0f00cdf5d17fba778a4d439f7f318cd1a6 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 16:54:24 -0700 Subject: [PATCH 12/87] removed mssql-tools installers, added sqlcmd connect test --- .travis.yml | 100 ++++++++++++++++++++++---------------------- Dockerfile-msphpsql | 12 +++--- 2 files changed, 57 insertions(+), 55 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25bb9835..1d3e9526 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,51 @@ -sudo: required - -os: linux -dist: trusty - -group: edge - -services: - - docker - -env: - global: - - REPORT_EXIT_STATUS=1 - - ACCEPT_EULA=Y - - PHPSQLDIR=/REPO/msphpsql-dev - - TEST_PHP_SQL_SERVER=sql - - SQLSRV_DBNAME=msphpsql_sqlsrv - - PDOSQLSRV_DBNAME=msphpsql_pdosqlsrv - -before_install: - - docker pull microsoft/mssql-server-linux - -install: - - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . - - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12@' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - -script: - - docker logs sql - - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev - - docker logs client - - docker ps -a - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client coveralls -e ./source/shared/ --gcov-options '\-lp' - - docker stop client - - docker ps -a - - -notifications: - email: false - +sudo: required + +os: linux +dist: trusty + +group: edge + +services: + - docker + +env: + global: + - REPORT_EXIT_STATUS=1 + - ACCEPT_EULA=Y + - PHPSQLDIR=/REPO/msphpsql-dev + - TEST_PHP_SQL_SERVER=sql + - SQLSRV_DBNAME=msphpsql_sqlsrv + - PDOSQLSRV_DBNAME=msphpsql_pdosqlsrv + +before_install: + - docker pull microsoft/mssql-server-linux + +install: + - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . + - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux + - docker exec -it sql /bin/bash/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password123 + +script: + - docker logs sql + + - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev + - docker logs client + - docker ps -a + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME + - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt + - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt + - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' + - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $SQLSRV_DBNAME + - docker exec client python ./test/functional/setup/cleanup_dbs.py -dbname $PDOSQLSRV_DBNAME + - docker exec client coveralls -e ./source/shared/ --gcov-options '\-lp' + - docker stop client + - docker ps -a + + +notifications: + email: false + diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 94351928..6b2275b3 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -26,7 +26,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \ ARG PHPSQLDIR=/REPO/msphpsql-dev ENV TEST_PHP_SQL_SERVER sql ENV TEST_PHP_SQL_UID sa -ENV TEST_PHP_SQL_PWD Password12@ +ENV TEST_PHP_SQL_PWD Password123 # set locale to utf-8 RUN locale-gen en_US.UTF-8 @@ -36,11 +36,11 @@ ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list -RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools -ENV PATH="/opt/mssql-tools/bin:${PATH}" -RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile -RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc -RUN /bin/bash -c "source ~/.bashrc" +RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql +#ENV PATH="/opt/mssql-tools/bin:${PATH}" +#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile +#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc +#RUN /bin/bash -c "source ~/.bashrc" #install coveralls From 10a99e4f8e2764c41c5acbfb897d96c8263a60a6 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 17:02:05 -0700 Subject: [PATCH 13/87] removed sqlcmd test --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d3e9526..a9910d6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,6 @@ before_install: install: - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - - docker exec -it sql /bin/bash/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password123 script: - docker logs sql From 190f52c9aeb460fe7a9e69f95029cf6c9bfe1abe Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 17:18:07 -0700 Subject: [PATCH 14/87] added entrypoint --- Dockerfile-msphpsql | 13 ++++++++----- .../setup/Dockerfile-msphpsql-entrypoint.sh | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 test/functional/setup/Dockerfile-msphpsql-entrypoint.sh diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 6b2275b3..cc804ee5 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -32,15 +32,18 @@ ENV TEST_PHP_SQL_PWD Password123 RUN locale-gen en_US.UTF-8 ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' +RUN chmod +x ./test/functional/setup/Dockerfile-msphpsql-entrypoint.sh +CMD /bin/bash ./test/functional/setup/Dockerfile-msphpsql-entrypoint.sh + #install ODBC driver RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list -RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql -#ENV PATH="/opt/mssql-tools/bin:${PATH}" -#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile -#RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc -#RUN /bin/bash -c "source ~/.bashrc" +RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools +ENV PATH="/opt/mssql-tools/bin:${PATH}" +RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile +RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc +RUN /bin/bash -c "source ~/.bashrc" #install coveralls diff --git a/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh b/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh new file mode 100644 index 00000000..adccb574 --- /dev/null +++ b/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh @@ -0,0 +1,10 @@ +set -e + +db_migrate="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123 -Q "select @@Version" + +until $db_migrate; do +>&2 echo "SQL Server is starting up. Running initial db configuration" +sleep 1 +done + +>&2 echo "SQL Server is up - starting app" From a3fa58a69928ca31894e1c53ebab4d896f46bbb0 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 17:20:20 -0700 Subject: [PATCH 15/87] fixed qoutes --- test/functional/setup/Dockerfile-msphpsql-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh b/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh index adccb574..541f34e9 100644 --- a/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh +++ b/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh @@ -1,6 +1,6 @@ set -e -db_migrate="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123 -Q "select @@Version" +db_migrate='/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123 -Q "select @@Version"' until $db_migrate; do >&2 echo "SQL Server is starting up. Running initial db configuration" From b4d71a1cdcb6d6dd1704c9a639158270a1424b75 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 28 Jul 2017 17:32:07 -0700 Subject: [PATCH 16/87] fixed path to entrypoint --- Dockerfile-msphpsql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index cc804ee5..62f92d22 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -32,8 +32,12 @@ ENV TEST_PHP_SQL_PWD Password123 RUN locale-gen en_US.UTF-8 ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' -RUN chmod +x ./test/functional/setup/Dockerfile-msphpsql-entrypoint.sh -CMD /bin/bash ./test/functional/setup/Dockerfile-msphpsql-entrypoint.sh +RUN mkdir -p $PHPSQLDIR +COPY . $PHPSQLDIR +WORKDIR $PHPSQLDIR/test/functional/setup/ + +RUN chmod +x ./Dockerfile-msphpsql-entrypoint.sh +CMD /bin/bash ./Dockerfile-msphpsql-entrypoint.sh #install ODBC driver RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - @@ -53,8 +57,6 @@ RUN pip install --upgrade pip && pip install cpp-coveralls #One option is to get source from zip file of repository. #another option is to copy source to build directory on image -RUN mkdir -p $PHPSQLDIR -COPY . $PHPSQLDIR WORKDIR $PHPSQLDIR/source/ From 73ad481f0dd9f1324b4bad08b62c5a2a4c546dbe Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 15:35:21 -0700 Subject: [PATCH 17/87] added network inspection and sqlcmd logins --- .travis.yml | 7 ++++--- Dockerfile-msphpsql | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9910d6e..94fc81d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,13 +26,14 @@ install: script: - docker logs sql - - - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev + - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev + - docker network ls + - docker inspect -f "{{ .HostConfig.Links }}" client - docker logs client - docker ps -a - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt + - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 62f92d22..49fd75cb 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -49,6 +49,8 @@ RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc RUN /bin/bash -c "source ~/.bashrc" +RUN chmod +x ./Dockerfile-msphpsql-entrypoint.sh +CMD /bin/bash ./Dockerfile-msphpsql-entrypoint.sh #install coveralls RUN pip install --upgrade pip && pip install cpp-coveralls From da77a1ec3c47f621babd6f6cf5d8c90fd1ac8d23 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 15:42:20 -0700 Subject: [PATCH 18/87] removed entryPoints call --- Dockerfile-msphpsql | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 49fd75cb..8ba38bbe 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -34,10 +34,7 @@ ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' RUN mkdir -p $PHPSQLDIR COPY . $PHPSQLDIR -WORKDIR $PHPSQLDIR/test/functional/setup/ -RUN chmod +x ./Dockerfile-msphpsql-entrypoint.sh -CMD /bin/bash ./Dockerfile-msphpsql-entrypoint.sh #install ODBC driver RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - @@ -49,9 +46,6 @@ RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc RUN /bin/bash -c "source ~/.bashrc" -RUN chmod +x ./Dockerfile-msphpsql-entrypoint.sh -CMD /bin/bash ./Dockerfile-msphpsql-entrypoint.sh - #install coveralls RUN pip install --upgrade pip && pip install cpp-coveralls From 897468626f4dc7a53816ae899c511414bd214424 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 16:03:50 -0700 Subject: [PATCH 19/87] added test for connection from client to server --- .travis.yml | 3 ++- TestSqlcmd.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 TestSqlcmd.sh diff --git a/.travis.yml b/.travis.yml index 94fc81d0..f3ce0c95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,8 @@ script: - docker network ls - docker inspect -f "{{ .HostConfig.Links }}" client - docker logs client - - docker ps -a + - docker ps -a + - docker exec client bash -c ./TestSqlcmd.sh - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh new file mode 100644 index 00000000..a9949b75 --- /dev/null +++ b/TestSqlcmd.sh @@ -0,0 +1,11 @@ +#!bin/bash +set -e + +$test = "sqlcmd -S sql -U sa -P Password123" + +until $test; do +>&2 echo "SQL Server is starting up. Running initial db configuration" +sleep 1 +done + +echo "SQL Server is up - starting app" \ No newline at end of file From ef1d84f3c590c98b51c54c2f879eb5b530bc4cc6 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 16:22:27 -0700 Subject: [PATCH 20/87] granted permission to connectivity --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f3ce0c95..6f369e92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ script: - docker inspect -f "{{ .HostConfig.Links }}" client - docker logs client - docker ps -a + - docker exec client 'chmod +x ./TestSqlcmd.sh' - docker exec client bash -c ./TestSqlcmd.sh - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME From de0d995c0af8a2f593f01a0ea483fc2d3b0a7b2f Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 16:50:39 -0700 Subject: [PATCH 21/87] fixing perm again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f369e92..548eab40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: - docker inspect -f "{{ .HostConfig.Links }}" client - docker logs client - docker ps -a - - docker exec client 'chmod +x ./TestSqlcmd.sh' + - docker exec client chmod +x ./TestSqlcmd.sh - docker exec client bash -c ./TestSqlcmd.sh - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME From 60a08bc969922f298f917c8a7686bd6d44cf07f4 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 16:58:42 -0700 Subject: [PATCH 22/87] fixed line ending --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 548eab40..ba961559 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ script: - docker logs client - docker ps -a - docker exec client chmod +x ./TestSqlcmd.sh - - docker exec client bash -c ./TestSqlcmd.sh + - docker exec client bash -c ./TestSqlcmd.sh - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt From a995aafa991ed65971903e188cdf7e913d58fa4c Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 17:08:32 -0700 Subject: [PATCH 23/87] fixed line ending in entrypoint --- TestSqlcmd.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index a9949b75..01a52073 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,11 +1,11 @@ -#!bin/bash -set -e - -$test = "sqlcmd -S sql -U sa -P Password123" - -until $test; do ->&2 echo "SQL Server is starting up. Running initial db configuration" -sleep 1 -done - +#!bin/bash +set -e + +$test = "sqlcmd -S sql -U sa -P Password123" + +until $test; do +>&2 echo "SQL Server is starting up. Running initial db configuration" +sleep 1 +done + echo "SQL Server is up - starting app" \ No newline at end of file From a5b5ba7fee4c20d3e4c2d56f1eb72ff8ceedd8c8 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 17:14:21 -0700 Subject: [PATCH 24/87] removed bin bash --- TestSqlcmd.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index 01a52073..33869d3f 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,4 +1,3 @@ -#!bin/bash set -e $test = "sqlcmd -S sql -U sa -P Password123" From 9f416608bb903175a4b9f3674b68124a7ef4cd4c Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 17:23:08 -0700 Subject: [PATCH 25/87] added path to sqlcmd --- TestSqlcmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index 33869d3f..cd21176e 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,6 +1,6 @@ set -e -$test = "sqlcmd -S sql -U sa -P Password123" +$test = "/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" until $test; do >&2 echo "SQL Server is starting up. Running initial db configuration" From c3b305e42c4fdf629d2f1c6b11fe8e3fa9bad147 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 17:44:11 -0700 Subject: [PATCH 26/87] removed extra space --- TestSqlcmd.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index cd21176e..228a2378 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,9 +1,9 @@ set -e -$test = "/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" +$test ='/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123' until $test; do ->&2 echo "SQL Server is starting up. Running initial db configuration" +>&2 echo "SQL Server is starting up" sleep 1 done From 50c26238ec27b4e8b39c6562eb6970573036cb30 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 17:58:28 -0700 Subject: [PATCH 27/87] a hopeless try --- TestSqlcmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index 228a2378..b1417b2b 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,6 +1,6 @@ set -e -$test ='/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123' +$test ="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" until $test; do >&2 echo "SQL Server is starting up" From 8983799f38875ced03357207d7622b140df9b017 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 31 Jul 2017 18:06:47 -0700 Subject: [PATCH 28/87] just exec sleep --- TestSqlcmd.sh | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh index b1417b2b..df4ea33a 100644 --- a/TestSqlcmd.sh +++ b/TestSqlcmd.sh @@ -1,10 +1 @@ -set -e - -$test ="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" - -until $test; do ->&2 echo "SQL Server is starting up" -sleep 1 -done - -echo "SQL Server is up - starting app" \ No newline at end of file +sleep 1m \ No newline at end of file From 98753f0998be86d7a626f9f1d8c73a0138cf4588 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 15:51:12 -0700 Subject: [PATCH 29/87] updated entrypoint --- .../setup/Dockerfile-msphpsql-entrypoint.sh => entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename test/functional/setup/Dockerfile-msphpsql-entrypoint.sh => entrypoint.sh (54%) diff --git a/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh b/entrypoint.sh similarity index 54% rename from test/functional/setup/Dockerfile-msphpsql-entrypoint.sh rename to entrypoint.sh index 541f34e9..c11ab9f7 100644 --- a/test/functional/setup/Dockerfile-msphpsql-entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,7 @@ set -e +isConnected="/opt/mssql-tools/bin/sqlcmd -S db -U sa -P Password123" -db_migrate='/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123 -Q "select @@Version"' - -until $db_migrate; do +until $isConnected; do >&2 echo "SQL Server is starting up. Running initial db configuration" sleep 1 done From b8b1246fe7e4a5ea2d8481a6fa6439404f44fb58 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 16:07:38 -0700 Subject: [PATCH 30/87] updated entrypoint --- .travis.yml | 6 +----- TestSqlcmd.sh | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 TestSqlcmd.sh diff --git a/.travis.yml b/.travis.yml index ba961559..c344eb88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,14 +27,10 @@ install: script: - docker logs sql - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - - docker network ls - - docker inspect -f "{{ .HostConfig.Links }}" client - - docker logs client - docker ps -a - - docker exec client chmod +x ./TestSqlcmd.sh - - docker exec client bash -c ./TestSqlcmd.sh - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME + - docker logs client - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' diff --git a/TestSqlcmd.sh b/TestSqlcmd.sh deleted file mode 100644 index df4ea33a..00000000 --- a/TestSqlcmd.sh +++ /dev/null @@ -1 +0,0 @@ -sleep 1m \ No newline at end of file From 6eb1e0311fd5f8f2c6bd24d6727956f595ba12ad Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 1 Aug 2017 16:09:56 -0700 Subject: [PATCH 31/87] 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 From bff31d8c2d99057ae5a910488ed7c19f5d9195c6 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 16:47:24 -0700 Subject: [PATCH 32/87] moved db setup to Dockerfile --- .travis.yml | 2 -- Dockerfile-msphpsql | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index c344eb88..c26bb22c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,6 @@ script: - docker logs sql - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - docker logs client - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 8ba38bbe..2dd67a82 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -27,24 +27,19 @@ ARG PHPSQLDIR=/REPO/msphpsql-dev ENV TEST_PHP_SQL_SERVER sql ENV TEST_PHP_SQL_UID sa ENV TEST_PHP_SQL_PWD Password123 +ENV SQLSRV_DBNAME msphpsql_sqlsrv +ENV PDOSQLSRV_DBNAME msphpsql_pdosqlsrv # set locale to utf-8 RUN locale-gen en_US.UTF-8 ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' -RUN mkdir -p $PHPSQLDIR -COPY . $PHPSQLDIR - - #install ODBC driver RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools ENV PATH="/opt/mssql-tools/bin:${PATH}" -RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile -RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc -RUN /bin/bash -c "source ~/.bashrc" #install coveralls RUN pip install --upgrade pip && pip install cpp-coveralls @@ -54,6 +49,8 @@ RUN pip install --upgrade pip && pip install cpp-coveralls #another option is to copy source to build directory on image +RUN mkdir -p $PHPSQLDIR +COPY . $PHPSQLDIR WORKDIR $PHPSQLDIR/source/ RUN chmod +x ./packagize.sh @@ -81,6 +78,14 @@ RUN sed -i -e 's/TARGET_DATABASE/msphpsql_sqlsrv/g' MsSetup.inc RUN sed -i -e 's/TARGET_USERNAME/'"$TEST_PHP_SQL_UID"'/g' MsSetup.inc RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc -ENV REPORT_EXIT_STATUS 1 +WORKDIR $PHPSQLDIR +RUN chmod +x ./entrypoint.sh +RUN bin/bash -c ./entrypoint.sh + +WORKDIR $PHPSQLDIR /test/functional/setup/ +python ./setup_dbs.py -dbname $SQLSRV_DBNAME +python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME + ENV TEST_PHP_EXECUTABLE /usr/bin/php +ENV REPORT_EXIT_STATUS 1 \ No newline at end of file From 7816db5710db95c14f9cb08ffd917d1aff442cf7 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 16:57:41 -0700 Subject: [PATCH 33/87] added RUN :) --- Dockerfile-msphpsql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 2dd67a82..5f2a1bfc 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -83,8 +83,8 @@ RUN chmod +x ./entrypoint.sh RUN bin/bash -c ./entrypoint.sh WORKDIR $PHPSQLDIR /test/functional/setup/ -python ./setup_dbs.py -dbname $SQLSRV_DBNAME -python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME +RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME +RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME ENV TEST_PHP_EXECUTABLE /usr/bin/php From 4822cc286c8edb956bd85535e232204a85bd99aa Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 17:35:03 -0700 Subject: [PATCH 34/87] debugging --- .travis.yml | 2 +- Dockerfile-msphpsql | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c26bb22c..feaf6731 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a - docker logs client - - docker exec client php ./test/functional/pdo_sqlsrv/*.phpt + - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 5f2a1bfc..377665f9 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -80,11 +80,11 @@ RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh -RUN bin/bash -c ./entrypoint.sh +RUN bin/bash -c "./entrypoint.sh" WORKDIR $PHPSQLDIR /test/functional/setup/ -RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME -RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME +#RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME +#RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME ENV TEST_PHP_EXECUTABLE /usr/bin/php From d3da0ceb686c427f85b3f139c56bce46fa6b5689 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 17:51:04 -0700 Subject: [PATCH 35/87] fixed the path bash :) --- .travis.yml | 2 +- Dockerfile-msphpsql | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index feaf6731..dcddf8f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,8 @@ before_install: - docker pull microsoft/mssql-server-linux install: - - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux + - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . script: - docker logs sql diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 377665f9..262120da 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -80,11 +80,11 @@ RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh -RUN bin/bash -c "./entrypoint.sh" +RUN /bin/bash -c ./entrypoint.sh WORKDIR $PHPSQLDIR /test/functional/setup/ -#RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME -#RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME +RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME +RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME ENV TEST_PHP_EXECUTABLE /usr/bin/php From ac630b050000c872003c4e69fbaf0bc45df60862 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 18:18:52 -0700 Subject: [PATCH 36/87] added CMD --- .travis.yml | 4 +++- Dockerfile-msphpsql | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index dcddf8f5..a8465962 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,13 +21,15 @@ before_install: - docker pull microsoft/mssql-server-linux install: - - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux + - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . script: - docker logs sql - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME + - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - docker logs client - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 262120da..d47b99a2 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -80,11 +80,7 @@ RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh -RUN /bin/bash -c ./entrypoint.sh - -WORKDIR $PHPSQLDIR /test/functional/setup/ -RUN python ./setup_dbs.py -dbname $SQLSRV_DBNAME -RUN python ./setup_dbs.py -dbname $PDOSQLSRV_DBNAME +CMD /bin/bash ./entrypoint.sh ENV TEST_PHP_EXECUTABLE /usr/bin/php From 177656d20cd5563b0f384ebf6da992568c7339f3 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Tue, 1 Aug 2017 18:23:16 -0700 Subject: [PATCH 37/87] fixed travis syntax --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a8465962..198698a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - docker pull microsoft/mssql-server-linux install: - - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux + - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . script: From 101eaf2c66e11dda701a1a21d0b5acf09b2399ed Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 09:46:59 -0700 Subject: [PATCH 38/87] passing arg to entrypoint --- Dockerfile-msphpsql | 10 ++++------ entrypoint.sh | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index d47b99a2..b38469bc 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -27,8 +27,6 @@ ARG PHPSQLDIR=/REPO/msphpsql-dev ENV TEST_PHP_SQL_SERVER sql ENV TEST_PHP_SQL_UID sa ENV TEST_PHP_SQL_PWD Password123 -ENV SQLSRV_DBNAME msphpsql_sqlsrv -ENV PDOSQLSRV_DBNAME msphpsql_pdosqlsrv # set locale to utf-8 RUN locale-gen en_US.UTF-8 @@ -78,10 +76,10 @@ RUN sed -i -e 's/TARGET_DATABASE/msphpsql_sqlsrv/g' MsSetup.inc RUN sed -i -e 's/TARGET_USERNAME/'"$TEST_PHP_SQL_UID"'/g' MsSetup.inc RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc -WORKDIR $PHPSQLDIR -RUN chmod +x ./entrypoint.sh -CMD /bin/bash ./entrypoint.sh - ENV TEST_PHP_EXECUTABLE /usr/bin/php +WORKDIR $PHPSQLDIR +RUN chmod +x ./entrypoint.sh +CMD /bin/bash ./entrypoint.sh TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD + ENV REPORT_EXIT_STATUS 1 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index c11ab9f7..00c0f152 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,9 @@ set -e -isConnected="/opt/mssql-tools/bin/sqlcmd -S db -U sa -P Password123" +isConnected="/opt/mssql-tools/bin/sqlcmd -S $1 -U $2 -P $3" until $isConnected; do ->&2 echo "SQL Server is starting up. Running initial db configuration" +>&2 echo "SQL Server is starting up..." sleep 1 done ->&2 echo "SQL Server is up - starting app" +>&2 echo "SQL Server is up!" From d559aed8f0cc2a76401f1d29829eefb2af1ccea3 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 09:53:52 -0700 Subject: [PATCH 39/87] added $ to variable --- Dockerfile-msphpsql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index b38469bc..b96640b2 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -80,6 +80,6 @@ ENV TEST_PHP_EXECUTABLE /usr/bin/php WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh -CMD /bin/bash ./entrypoint.sh TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD +CMD /bin/bash ./entrypoint.sh $TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD ENV REPORT_EXIT_STATUS 1 \ No newline at end of file From 154e4cbed889d9bbcc9dc7d1e8909c670572df67 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 10:02:41 -0700 Subject: [PATCH 40/87] clean up --- .travis.yml | 1 - Dockerfile-msphpsql | 2 -- 2 files changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 198698a2..d210b552 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,6 @@ install: - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . script: - - docker logs sql - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index b96640b2..03da2c9d 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -76,8 +76,6 @@ RUN sed -i -e 's/TARGET_DATABASE/msphpsql_sqlsrv/g' MsSetup.inc RUN sed -i -e 's/TARGET_USERNAME/'"$TEST_PHP_SQL_UID"'/g' MsSetup.inc RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc -ENV TEST_PHP_EXECUTABLE /usr/bin/php - WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh CMD /bin/bash ./entrypoint.sh $TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD From bcd16ef35b23960f928ac056d7c831e1bff01a76 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 10:06:27 -0700 Subject: [PATCH 41/87] deleted linebreaks --- Dockerfile-msphpsql | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 03da2c9d..6ec10899 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -44,9 +44,7 @@ RUN pip install --upgrade pip && pip install cpp-coveralls #Either Install git / download zip (One can see other strategies : https://ryanfb.github.io/etc/2015/07/29/git_strategies_for_docker.html ) #One option is to get source from zip file of repository. - #another option is to copy source to build directory on image - RUN mkdir -p $PHPSQLDIR COPY . $PHPSQLDIR WORKDIR $PHPSQLDIR/source/ From 1d7d15a451cd9d2520649d70ace441176ba5035e Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 10:15:47 -0700 Subject: [PATCH 42/87] Debugging --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d210b552..e78fdc28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,9 +27,9 @@ install: script: - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a + - docker logs client - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker logs client - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' From 29acb1bb82c5aa34dbc811c2db22de04d181d0ab Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 10:23:52 -0700 Subject: [PATCH 43/87] php exe set --- Dockerfile-msphpsql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 6ec10899..72b50909 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -78,4 +78,5 @@ WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh CMD /bin/bash ./entrypoint.sh $TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD -ENV REPORT_EXIT_STATUS 1 \ No newline at end of file +ENV REPORT_EXIT_STATUS 1 +ENV TEST_PHP_EXECUTABLE /usr/bin/php \ No newline at end of file From 13a5bbb817b6a247909efd57bf9e35888d08c66e Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 10:25:26 -0700 Subject: [PATCH 44/87] debugging --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e78fdc28..4ecd0d48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ script: - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt + - docker logs client - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' From b7f7708817cabf76bb3ff10aa0fcb72b35bfe76f Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 12:38:18 -0700 Subject: [PATCH 45/87] added ping to the entrypoint too --- entrypoint.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 00c0f152..c3f32e9b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,11 @@ set -e -isConnected="/opt/mssql-tools/bin/sqlcmd -S $1 -U $2 -P $3" + +while ! ping -c3 $1 &>/dev/null; do echo "Ping Fail - `date`"; done ; echo "Host Found - `date`"; + +testConnection="/opt/mssql-tools/bin/sqlcmd -S $1 -U $2 -P $3" -until $isConnected; do ->&2 echo "SQL Server is starting up..." +until $testConnection; do +>&2 echo "SQL Server is starting up.." sleep 1 done From 651b72cef208ea5d30d7404e4508b75dd271f724 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 12:47:39 -0700 Subject: [PATCH 46/87] removed ping --- Dockerfile-msphpsql | 2 +- entrypoint.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile-msphpsql b/Dockerfile-msphpsql index 72b50909..6cff1116 100644 --- a/Dockerfile-msphpsql +++ b/Dockerfile-msphpsql @@ -76,7 +76,7 @@ RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc WORKDIR $PHPSQLDIR RUN chmod +x ./entrypoint.sh -CMD /bin/bash ./entrypoint.sh $TEST_PHP_SQL_SERVER $TEST_PHP_SQL_UID $TEST_PHP_SQL_PWD +CMD /bin/bash ./entrypoint.sh ENV REPORT_EXIT_STATUS 1 ENV TEST_PHP_EXECUTABLE /usr/bin/php \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index c3f32e9b..bc9bf5b6 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,6 @@ set -e -while ! ping -c3 $1 &>/dev/null; do echo "Ping Fail - `date`"; done ; echo "Host Found - `date`"; - -testConnection="/opt/mssql-tools/bin/sqlcmd -S $1 -U $2 -P $3" +testConnection="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Pasword123" until $testConnection; do >&2 echo "SQL Server is starting up.." From 05e4cf350afa2bfe470a9186cd73b78762f7b470 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 12:48:41 -0700 Subject: [PATCH 47/87] fixed typo --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index bc9bf5b6..ebe17d5f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ set -e -testConnection="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Pasword123" +testConnection="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" until $testConnection; do >&2 echo "SQL Server is starting up.." From 6b6e840b45899ece9e75a361b41978d8dbdf2f56 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 12:55:12 -0700 Subject: [PATCH 48/87] line ending --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index ebe17d5f..318b2611 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,5 @@ set -e - + testConnection="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" until $testConnection; do From 0fc91ae1f110c493666fe608a3a5825718d15a14 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Wed, 2 Aug 2017 13:09:30 -0700 Subject: [PATCH 49/87] added before_script sleep to travis too --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4ecd0d48..bf0062d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,9 @@ install: - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password123' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux - docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql . +before_script: + - sleep 30 + script: - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a From 7c305fadbceb496357a066f971cf943138c17ab6 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Thu, 3 Aug 2017 13:47:56 -0700 Subject: [PATCH 50/87] limited the loop to 10 times, max 60 sec wait --- entrypoint.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 318b2611..ffa47b4b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,9 +2,15 @@ set -e testConnection="/opt/mssql-tools/bin/sqlcmd -S sql -U sa -P Password123" -until $testConnection; do +for run in {1..10}; do + >&2 echo "SQL Server is starting up.." -sleep 1 +if $testConnection; then + >&2 echo "SQL Server is up!" + break; +else + sleep 6 +fi done ->&2 echo "SQL Server is up!" + From 6c64e4a27fb98d3f5f896ce589e72144d084a3e0 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Thu, 3 Aug 2017 13:49:32 -0700 Subject: [PATCH 51/87] fixed the path --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf0062d6..4a31ae58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ script: - docker logs client - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt + - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker logs client - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' From 4f47277fa6686c062659da801ca1b049b0c595c2 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Thu, 3 Aug 2017 18:02:16 -0700 Subject: [PATCH 52/87] test travis_retry --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a31ae58..a8dee75b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,11 +31,10 @@ script: - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a - docker logs client - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - - docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME - - docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt - - docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - - docker logs client + - travis_retry docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME + - travis_retry docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME + - travis_retry docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/functional/pdo_sqlsrv/*.phpt + - travis_retry docker exec client php ./source/sqlsrv/run-tests.php ./test/functional/sqlsrv/*.phpt - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' - docker exec client bash -c 'for f in ./test/functional/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true' From 3fd4027bad15d5af96b0db64eda78095f09bbf50 Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Fri, 4 Aug 2017 10:08:51 -0700 Subject: [PATCH 53/87] added --no-sandox to mac instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95fe64d9..b75f9419 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release brew update - brew install msodbcsql + brew install --no-sandbox msodbcsql brew install mssql-tools brew install autoconf From b770d99e9532ba5bc4d0e0412390206ef595a27b Mon Sep 17 00:00:00 2001 From: Hadis Fard Date: Fri, 4 Aug 2017 10:25:40 -0700 Subject: [PATCH 54/87] added retry to docker run client as well --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a8dee75b..c290dccf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_script: - sleep 30 script: - - docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev + - travis_retry docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a - docker logs client - travis_retry docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME From fdc1d419a59c7d57c4494e776eaa1b93ade2176f Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Wed, 9 Aug 2017 16:06:38 -0700 Subject: [PATCH 55/87] Update README.md --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b75f9419..0756cdc7 100644 --- a/README.md +++ b/README.md @@ -306,17 +306,20 @@ On all systems, run: **Ubuntu and Debian** - sudo service apache2 restart + sudo systemctl restart apache2 **RedHat** - sudo apachectl restart + sudo systemctl restart httpd + +Note: On RedHat, SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to a database through SELinux, run the following command: + + sudo setsebool -P httpd_can_network_connect_db 1 **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` ### 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. From 282b88d9268a5e8d859abd098fec52002b6d503d Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 11 Aug 2017 12:49:54 -0700 Subject: [PATCH 56/87] Python scripts for building extensions for PHP 7+ in Windows --- buildscripts/builddrivers.py | 268 +++++++++++++++++++++ buildscripts/buildtools.py | 437 +++++++++++++++++++++++++++++++++++ 2 files changed, 705 insertions(+) create mode 100644 buildscripts/builddrivers.py create mode 100644 buildscripts/buildtools.py diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py new file mode 100644 index 00000000..03b0c9f6 --- /dev/null +++ b/buildscripts/builddrivers.py @@ -0,0 +1,268 @@ +#!/usr/bin/python +######################################################################################### +# +# Description: This script helps to build drivers in a Windows environment for PHP 7+ (32-bit/64-bit) +# +# Requirement: +# python 3.4 +# PHP SDK and PHP Source +# Driver source code folder / GitHub repository +# Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) +# +# Execution: Run with command line with required options. +# Examples: +# py builddrivers.py (for interactive mode) +# py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no +# py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=all --GITHUB=yes +# +# Output: Build the drivers using PHP SDK. When running locally, if build is unsuccessful, +# the log file will be launched for examination. Otherwise, the drivers will be renamed +# and copied to the designated location(s). +# +############################################################################################# + +import sys +import shutil +import os.path +import argparse +from buildtools import BuildUtil + +class BuildDriver(object): + """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: + + Attributes: + phpver # PHP version, e.g. 7.1.*, 7.2.* etc. + driver # all, sqlsrv, or pdo_sqlsrv + arch # x64 or x86 + thread # nts or ts + debug # whether debug is enabled + repo # GitHub repository + branch # GitHub repository branch + download_source # download source from GitHub or not + package # package name for the binaries + remote_path # remote destination to where the drivers will be placed (None for local builds) + local # whether the build is local + source_path # path to a local source folder + """ + + def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, package, path): + self.util = BuildUtil(phpver, driver, arch, thread, debug) + self.repo = repo + self.branch = branch + self.download_source = download + self.package = package + self.remote_path = path + self.local = path is None # the default path is None, which means running locally + self.rebuild = False + self.make_clean = False + self.source_path = None # None initially but will be set later if not downloading from GitHub + + def show_config(self): + print('PHP Version: ', self.util.phpver) + print('Arch: ', self.util.arch) + print('Thread: ', self.util.thread) + print('Driver: ', self.util.driver) + print('Debug enabled: ', self.util.debug_enabled) + + def clean_or_remove(self, root_dir, work_dir): + """Check if php source directory already exists. If so, prompt user whether to rebuild, clean, or superclean, meaning to remove the entire php source directory.""" + phpsrc = self.util.phpsrc_root(root_dir) + if os.path.exists( phpsrc ): + print(phpsrc + " exists.") + choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") + self.make_clean = False + if choice == 'r': + print('Will rebuild the binaries') + self.util.remove_prev_build(root_dir) + elif choice == 'c': + print('Will make clean') + self.make_clean = True + # this step is necessary in case the user has changed the configuration + self.util.remove_old_builds(root_dir) + else: + print('Will remove ' + phpsrc) + os.system('RMDIR /s /q ' + phpsrc) + + os.chdir(work_dir) + + def build_extensions(self, dest, logfile): + """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations.""" + work_dir = os.path.dirname(os.path.realpath(__file__)) + + if self.download_source: + # This will download from the specified branch on GitHub repo and copy the source to the working directory + self.util.download_msphpsql_source(repo, branch) + else: + # This case only happens when building locally (interactive mode) + while True: + if self.source_path is None: + source = input('Enter the full path to the Source folder: ') + else: + source = input("Hit ENTER to reuse '" + self.source_path + "' or provide another path to the Source folder: ") + if len(source) == 0: + source = self.source_path + + if os.path.exists( source ): + self.source_path = source + break + else: + print('The path provided does not exist. Please re-enter.') + + print('Copying source files from', source) + + os.system('ROBOCOPY ' + source + '\shared ' + work_dir + '\Source\shared /xx /xo ') + os.system('ROBOCOPY ' + source + '\sqlsrv ' + work_dir + '\Source\sqlsrv /xx /xo ') + os.system('ROBOCOPY ' + source + '\pdo_sqlsrv ' + work_dir + '\Source\pdo_sqlsrv /xx /xo ') + + print('Start building PHP with the extension...') + + self.util.build_drivers(self.make_clean, dest, logfile) + + if dest is None: + # This indicates the script is NOT running locally, and that + # the drivers should be in the working directory + + # Make sure drivers path is defined + if self.remote_path is None: + print('Errors: Drivers destination should be defined! Do nothing.') + else: + OS_folder = "Windows" # hardcode this since this script is only run in Windows + dest_drivers = os.path.join(self.remote_path, 'PHP', 'Drivers', self.package, OS_folder, self.util.major_version(), self.util.arch) + dest_symbols = os.path.join(dest_drivers, 'Symbols') + + # All intermediate directories will be created in order to create the leaf directory + if os.path.exists(dest_symbols) == False: + os.makedirs(dest_symbols) + + # Now copy all the binaries + if self.util.driver == 'all': + self.util.copy_binary(work_dir, dest_drivers, 'sqlsrv', '.dll') + self.util.copy_binary(work_dir, dest_symbols, 'sqlsrv', '.pdb') + self.util.copy_binary(work_dir, dest_drivers, 'pdo_sqlsrv', '.dll') + self.util.copy_binary(work_dir, dest_symbols, 'pdo_sqlsrv', '.pdb') + else: + self.util.copy_binary(work_dir, dest_drivers, self.util.driver, '.dll') + self.util.copy_binary(work_dir, dest_symbols, self.util.driver, '.pdb') + + + def build(self): + """This is the main entry point of building drivers for PHP.""" + self.show_config() + + work_dir = os.path.dirname(os.path.realpath(__file__)) + root_dir = 'C:' + os.sep + + quit = False + while not quit: + if not self.rebuild and self.local: + self.clean_or_remove(root_dir, work_dir) + + logfile = self.util.get_logfile_name() + + try: + dest = None + if self.local: + dest = root_dir + + self.build_extensions(dest, logfile) + print('Build Completed') + except: + print('Something went wrong. Build incomplete.') + if self.local: # display log file only when building locally + os.startfile(os.path.join(root_dir, 'php-sdk', logfile)) + os.chdir(work_dir) + break + + # Only ask when building locally + if self.local: + choice = input("Rebuild the same configuration(yes) or quit (no) [yes/no]: ") + + if choice.lower() == 'yes' or choice.lower() == 'y' or choice.lower() == '': + print('Rebuilding drivers...') + self.make_clean = False + self.rebuild = True + self.util.remove_prev_build(root_dir) + else: + quit = True + else: + quit = True + + os.chdir(work_dir) + +def validate_input(question, values): + """Return the user selected value, and it must be valid based on *values*.""" + while True: + options = values.split('/') + prompt = '[' + values + ']' + value = input(question + prompt + ': ') + value = value.lower() + if not value in options: + print("An invalid choice is entered. Choose from", prompt) + else: + break + return value + +################################### Main Function ################################### +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('-v', '--PHPVER', help="PHP version, e.g. 7.1.*, 7.2.* etc.") + parser.add_argument('-a', '--ARCH', choices=['x64', 'x86']) + parser.add_argument('-t', '--THREAD', choices=['nts', 'ts']) + parser.add_argument('-d', '--DRIVER', choices=['all', 'sqlsrv', 'pdo_sqlsrv']) + parser.add_argument('-m', '--DEBUG', default='no', choices=['yes', 'no'], help="enable debug mode") + parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository") + parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") + parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") + parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") + parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers") + + args = parser.parse_args() + + phpver = args.PHPVER + arch = args.ARCH + thread = args.THREAD + driver = args.DRIVER + debug = args.DEBUG == 'yes' + repo = args.REPO + branch = args.BRANCH + download = args.GITHUB.lower() == 'yes' + path = args.PATH + package = args.PACKAGE + + if phpver is None: + # assuming it is building drivers locally when required to prompt + # thus will not prompt for drivers' destination path, which is None by default + phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") + arch_version = input("Want to build 64-bit [y/n]: ") + thread = validate_input("Thread safe? ", "nts/ts") + driver = validate_input("Driver to build? ", "all/sqlsrv/pdo_sqlsrv") + debug_mode = input("Want to build debug [y/n]? ") + + answer = input("Download source from a GitHub repo [y/n]? ") + download = False + if answer == 'yes' or answer == 'y' or answer == '': + download = True + repo = input("Name of the repo (hit enter for 'Microsoft'): ") + branch = input("Name of the branch (hit enter for 'dev'): ") + if repo == '': + repo = 'Microsoft' + if branch == '': + branch = 'dev' + + arch_version = arch_version.lower() + arch = 'x64' if arch_version == 'yes' or arch_version == 'y' or arch_version == '' else 'x86' + + debug_mode = debug_mode.lower() + debug = debug_mode == 'yes' or debug_mode == 'y' or debug_mode == '' + + builder = BuildDriver(phpver, + driver, + arch, + thread, + debug, + repo, + branch, + download, + package, + path) + builder.build() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py new file mode 100644 index 00000000..17f2d4a9 --- /dev/null +++ b/buildscripts/buildtools.py @@ -0,0 +1,437 @@ +#!/usr/bin/python +######################################################################################### +# +# Description: The class BuildUtil will build Microsoft SQL Server PHP 7+ Drivers +# for 32 bit and 64 bit. +# +# Requirement: +# python 3.4 +# PHP SDK and PHP Source +# Driver source code folder +# Git for Windows +# Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) +# +# Output: The drivers will be renamed and copied to the specified location. +# +############################################################################################# + +import shutil +import os.path +import stat +import datetime +import urllib.request +import zipfile + +class BuildUtil(object): + """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: + + Attributes: + phpver # PHP version, e.g. 7.1.*, 7.2.* etc. + driver # all, sqlsrv, or pdo_sqlsrv + arch # x64 or x86 + thread # nts or ts + debug_enabled # whether debug is enabled + """ + + def __init__(self, phpver, driver, arch, thread, debug_enabled = False): + self.phpver = phpver + self.driver = driver.lower() + self.arch = arch.lower() + self.thread = thread.lower() + self.debug_enabled = debug_enabled + + def major_version(self): + """Return the major version number based on the PHP version.""" + return self.phpver[0:3] + + def version_label(self): + """Return the version label based on the PHP version.""" + major_ver = self.major_version() + + if major_ver == '7.0': + version = major_ver[0] + else: + version = major_ver[0] + major_ver[2] + return version + + def driver_name(self, driver, suffix): + """Return the *driver* name with *suffix* after PHP is successfully compiled.""" + return 'php_' + driver + suffix + + def driver_new_name(self, driver, suffix): + """Return the *driver* name with *suffix* based on PHP version and thread.""" + version = self.version_label() + return 'php_' + driver + '_' + version + '_' + self.thread + suffix + + def compiler_version(self): + """Return the appropriate compiler version based on PHP version.""" + VC = 'vc14' + version = self.version_label() + if version >= '72': # Compiler version for PHP 7.2 or above + VC = 'vc15' + return VC + + def phpsrc_root(self, sdk_dir): + """Return the path to the PHP source folder based on *sdk_dir*.""" + vc = self.compiler_version() + return os.path.join(sdk_dir, 'php-sdk', 'phpdev', vc, self.arch, 'php-'+self.phpver+'-src') + + def build_abs_path(self, sdk_dir): + """Return the absolute path to the PHP build folder based on *sdk_dir*.""" + phpsrc = self.phpsrc_root(sdk_dir) + + build_dir = 'Release' + if self.debug_enabled: + build_dir = 'Debug' + + if self.thread == 'ts': + build_dir = build_dir + '_TS' + + if self.arch == 'x64': + build_dir = self.arch + os.sep + build_dir + + return os.path.join(phpsrc, build_dir) + + def remove_old_builds(self, sdk_dir): + """Remove the extensions, e.g. the driver subfolders in php-7.*-src\ext.""" + print('Removing old builds...') + + phpsrc = self.phpsrc_root(sdk_dir) + ext_path = os.path.join(phpsrc, 'ext') + if os.path.exists( ext_path ): + shutil.rmtree(os.path.join(ext_path, 'sqlsrv'), ignore_errors=True) + shutil.rmtree(os.path.join(ext_path, 'pdo_sqlsrv'), ignore_errors=True) + + if self.arch == 'x64': + shutil.rmtree(os.path.join(phpsrc, self.arch), ignore_errors=True) + else: + shutil.rmtree(os.path.join(phpsrc, 'Debug'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Debug_TS'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Release'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) + + def remove_prev_build(self, sdk_dir): + """Remove all binaries and source code in the Release* or Debug* folders""" + print('Removing previous build...') + build_dir = self.build_abs_path(sdk_dir) + os.chdir(build_dir) + os.system('DEL *sqlsrv*') + + # remove the extensions in the phpsrc's release* or debug* folder's ext subfolder + release_ext_path = os.path.join(build_dir, 'ext') + if os.path.exists( release_ext_path ): + shutil.rmtree(os.path.join(release_ext_path, 'sqlsrv'), ignore_errors=True) + shutil.rmtree(os.path.join(release_ext_path, 'pdo_sqlsrv'), ignore_errors=True) + + # next remove the binaries too + os.chdir(release_ext_path) + os.system('DEL *sqlsrv*') + + @staticmethod + def get_logfile_name(): + """Return the filename for the log file based on timestamp.""" + return 'Build_' + datetime.datetime.now().strftime("%Y%m%d_%H%M") + '.log' + + @staticmethod + def update_file_content(file, search_str, new_str): + """Find *search_str* and replace it by *new_str* in a *file*""" + os.chmod(file, stat.S_IWRITE) + f = open(file, 'r') + filedata = f.read() + updatedata = filedata.replace(search_str, new_str) + f = open(file, 'w') + f.write(updatedata) + f.close() + + @staticmethod + def generateMMDD(): + """Return the generated Microsoft PHP Build Version Number""" + d = datetime.date.today() + + startYear = 2009 + startMonth = 4 + passYear = int( '%02d' % d.year ) - startYear + passMonth = int( '%02d' % d.month ) - startMonth + MM = passYear * 12 + passMonth + dd = d.day + + MMDD = "" + str( MM ) + if( dd < 10 ): + return MMDD + "0" + str( dd ) + else: + return MMDD + str( dd ) + + @staticmethod + def get_driver_version(version_file): + """Read the *version_file* and return the driver version.""" + with open(version_file) as f: + for line in f: + if 'SQLVERSION_MAJOR' in line: # major version + major = line.split()[2] + elif 'SQLVERSION_MINOR' in line: # minor version + minor = line.split()[2] + elif 'SQLVERSION_PATCH' in line: # patch + patch = line.split()[2] + break + + return major + '.' + minor + '.' + patch + + @staticmethod + def write_lines_to_copy_source(driver, file): + """Write to file the commands to copy *driver* source.""" + source = '%currDir%' + os.sep + 'Source' + os.sep + driver + dest = '%phpSrc%' + os.sep + 'ext' + os.sep + driver + file.write('@CALL ROBOCOPY ' + source + ' ' + dest + ' /s /xx /xo' + os.linesep) + + source = '%currDir%' + os.sep + 'Source' + os.sep + 'shared' + dest = '%phpSrc%' + os.sep + 'ext' + os.sep + driver + os.sep + 'shared' + file.write('@CALL ROBOCOPY ' + source + ' ' + dest + ' /s /xx /xo' + os.linesep) + + @staticmethod + def download_msphpsql_source(repo, branch, dest_folder = 'Source', clean_up = True): + """Download to *dest_folder* the msphpsql archive of the specified GitHub *repo* and *branch*.""" + try: + work_dir = os.path.dirname(os.path.realpath(__file__)) + + temppath = os.path.join(work_dir, 'temp') + if os.path.exists(temppath): + shutil.rmtree(temppath) + os.makedirs(temppath) + os.chdir(temppath) + + file = branch + '.zip' + url = 'https://github.com/' + repo + '/msphpsql/archive/' + branch + '.zip' + + print('Downloading ' + url + ' ...') + try: + with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file: + shutil.copyfileobj(response, out_file) + except: + print ("Resort to skip ssl verifcation...") + # need to skip ssl verifcation on some agents + # see https://www.python.org/dev/peps/pep-0476/ + with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as response, open(file, 'wb') as out_file: + shutil.copyfileobj(response, out_file) + + print('Extracting ' + file + ' ...') + zip = zipfile.ZipFile(file) + zip.extractall() + zip.close() + + msphpsqlFolder = os.path.join(temppath, 'msphpsql-' + branch) + source = os.path.join(msphpsqlFolder, 'source') + os.chdir(work_dir) + + os.system('ROBOCOPY ' + source + '\shared ' + dest_folder + '\shared /xx /xo') + os.system('ROBOCOPY ' + source + '\pdo_sqlsrv ' + dest_folder + '\pdo_sqlsrv /xx /xo') + os.system('ROBOCOPY ' + source + '\sqlsrv ' + dest_folder + '\sqlsrv /xx /xo') + + if clean_up: + shutil.rmtree(temppath) + + except: + print('Error occurred when downloading source') + raise + + def update_driver_source(self, source_dir, driver): + """Update the *driver* source in *source_path* with the latest version, file descriptions, etc.""" + driver_dir = os.path.join(source_dir, driver) + + # Update Template.rc + template_file = os.path.join(driver_dir, 'template.rc') + if driver == 'sqlsrv': + drivername = self.driver_new_name(driver, '.dll') + self.update_file_content(template_file, 'FILE_NAME \"\\0\"', '"' + drivername + '\\0"') + self.update_file_content(template_file, '\"Microsoft Drivers for PHP for SQL Server\\0\"', '"Microsoft Drivers for PHP for SQL Server (SQLSRV Driver)\\0"') + elif driver == 'pdo_sqlsrv': + drivername = self.driver_new_name(driver, '.dll') + self.update_file_content(template_file, 'FILE_NAME \"\\0\"', '"' + drivername + '\\0"') + self.update_file_content(template_file, '\"Microsoft Drivers for PHP for SQL Server\\0\"', '"Microsoft Drivers for PHP for SQL Server (PDO Driver)\\0"') + + # Update Version.h + version_file = os.path.join(source_dir, 'shared', 'version.h') + build_number = self.generateMMDD() + self.update_file_content(version_file, 'SQLVERSION_BUILD 0', 'SQLVERSION_BUILD ' + build_number) + + # get the latest version + version = self.get_driver_version(version_file) + '.' + build_number + print('Driver version is: ', version) + + # Update CREDIT file + credits_file = os.path.join(driver_dir, 'CREDITS') + if driver == 'sqlsrv': + self.update_file_content(credits_file, 'Microsoft Drivers for PHP for SQL Server', 'Microsoft Drivers ' + version + ' for PHP for SQL Server (' + self.driver.upper() + ' driver)') + elif driver == 'pdo_sqlsrv': + self.update_file_content(credits_file, 'Microsoft Drivers for PHP for SQL Server (PDO driver)', 'Microsoft Drivers ' + version + ' for PHP for SQL Server (' + self.driver.upper() + ' driver)') + + def generate_build_options(self): + """Return the generated build configuration and arguments""" + cmd_line = '' + if self.debug_enabled: + cmd_line = ' --enable-debug ' + + if self.driver == 'all': + cmd_line = ' --enable-sqlsrv=shared --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line + else: + if self.driver == 'sqlsrv': + cmd_line = ' --enable-sqlsrv=shared ' + cmd_line + else: # pdo_sqlsrv + cmd_line = ' --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line + + cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi' + cmd_line + ' --disable-ipv6 --with-odbcver=0x0380 --enable-embed' + if self.thread == 'nts': + cmd_line = cmd_line + ' --disable-zts' + return cmd_line + + def create_local_batch_file(self, make_clean, cmd_line, log_file): + """Generate the batch file to be picked up by the PHP starter script.""" + filename = 'phpsdk-build-task.bat' + print('Generating ', filename) + try: + file = open(filename, 'w') + file.write('@ECHO OFF' + os.linesep) + file.write('SET currDir=%CD%' + os.linesep) + file.write('SET LOG_NAME=%currDir%\\' + log_file + os.linesep) + file.write('@CALL phpsdk_buildtree phpdev > %LOG_NAME% 2>&1' + os.linesep) + + # for PHP version with release tags, such as 'RC', 'beta', etc. + # we need to remove the hyphen '-' between the version number and tag + # because in https://github.com/php/php-src the released tags have no hyphens + + php_tag = 'php-' + self.phpver.replace('-', '') + php_src = 'php-' + self.phpver +'-src' + + # if not exists, check out the specified tag + file.write('IF NOT EXIST ' + php_src + ' @CALL git clone -b ' + php_tag + ' --depth 1 --single-branch https://github.com/php/php-src.git ' + php_src + os.linesep) + file.write('CD ' + php_src + os.linesep) + file.write('SET phpSrc=%CD%' + os.linesep) + file.write('@CALL phpsdk_deps -u >> %LOG_NAME% 2>&1' + os.linesep) + + # copy source files to extension + if self.driver == 'all': + self.write_lines_to_copy_source('sqlsrv', file) + self.write_lines_to_copy_source('pdo_sqlsrv', file) + else: + self.write_lines_to_copy_source(self.driver, file) + + # configure and build + file.write('@CALL buildconf --force >> %LOG_NAME% 2>&1' + os.linesep) + file.write('@CALL ' + cmd_line + ' >> %LOG_NAME% 2>&1' + os.linesep) + if make_clean: + file.write('nmake clean >> %LOG_NAME% 2>&1' + os.linesep) + file.write('nmake >> %LOG_NAME% 2>&1' + os.linesep) + file.write('exit' + os.linesep) + file.close() + return filename + except: + print('Cannot create ', filename) + + def build_drivers(self, make_clean = False, dest = None, log_file = None): + """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder exists in the working directory, and this folder will be removed when the build is complete.""" + work_dir = os.path.dirname(os.path.realpath(__file__)) + + # First, update the driver source file contents + source_dir = os.path.join(work_dir, 'Source') + if self.driver == 'all': + self.update_driver_source(source_dir, 'sqlsrv') + self.update_driver_source(source_dir, 'pdo_sqlsrv') + else: + self.update_driver_source(source_dir, self.driver) + + # Next, generate the build configuration and arguments + cmd_line = self.generate_build_options() + print('cmd_line: ' + cmd_line) + + # Generate a batch file based on the inputs + if log_file is None: + log_file = self.get_logfile_name() + + batch_file = self.create_local_batch_file(make_clean, cmd_line, log_file) + + # Reference: https://github.com/OSTC/php-sdk-binary-tools + # Clone the master branch of PHP sdk if the directory does not exist + print('Downloading the latest php SDK...') + + # if *dest* is None, simply use the current working directory + sdk_dir = dest + copy_to_ext = True # this determines where to copy the binaries to + if dest is None: + sdk_dir = work_dir + copy_to_ext = False + + phpSDK = os.path.join(sdk_dir, 'php-sdk') + if not os.path.exists( phpSDK ): + os.system('git clone https://github.com/OSTC/php-sdk-binary-tools.git --branch master --single-branch --depth 1 ' + phpSDK) + os.chdir(phpSDK) + os.system('git pull ') + + # Copy the generated batch file to phpSDK for the php starter script + shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + shutil.move(source_dir, phpSDK) + + # Invoke phpsdk--.bat + vc = self.compiler_version() + starter_script = 'phpsdk-' + vc + '-' + self.arch + '.bat' + print('Running starter script: ', starter_script) + os.system(starter_script + ' -t ' + batch_file) + + # Now we can safely remove the Source folder, because its contents have + # already been modified when building the extensions + shutil.rmtree(os.path.join(phpSDK, 'Source'), ignore_errors=True) + + # Next, rename the newly compiled PHP extensions + self.rename_binaries(sdk_dir) + + # Final step, copy the binaries to the right place + self.copy_binaries(sdk_dir, copy_to_ext) + + def rename_binary(self, path, driver, suffix): + """Rename sqlsrv or pdo_sqlsrv binary.""" + driver_old_name = self.driver_name(driver, suffix) + driver_new_name = self.driver_new_name(driver, suffix) + + os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) + + def rename_binaries(self, sdk_dir): + """Rename the sqlsrv and/or pdo_sqlsrv binaries based on PHP version and thread, including pdb files.""" + + # Derive the path to where the extensions are located + ext_dir = self.build_abs_path(sdk_dir) + print("Renaming binaries in ", ext_dir) + + if self.driver == 'all': + self.rename_binary(ext_dir, 'sqlsrv', '.dll') + self.rename_binary(ext_dir, 'sqlsrv', '.pdb') + self.rename_binary(ext_dir, 'pdo_sqlsrv', '.dll') + self.rename_binary(ext_dir, 'pdo_sqlsrv', '.pdb') + else: + self.rename_binary(ext_dir, self.driver, '.dll') + self.rename_binary(ext_dir, self.driver, '.pdb') + + def copy_binary(self, from_dir, dest_dir, driver, suffix): + """Copy sqlsrv or pdo_sqlsrv binary to *dest_dir*.""" + binary = self.driver_new_name(driver, suffix) + shutil.copy2(os.path.join(from_dir, binary), dest_dir) + + def copy_binaries(self, sdk_dir, copy_to_ext): + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, to the right place.""" + build_dir = self.build_abs_path(sdk_dir) + print('Copying the binaries from', build_dir) + if copy_to_ext: + dest_dir = os.path.join(build_dir, 'ext') + else: + # Simply make a copy of the binaries in sdk_dir + dest_dir = sdk_dir + + print('Destination:', dest_dir) + + # Now copy the binaries + if self.driver == 'all': + self.copy_binary(build_dir, dest_dir, 'sqlsrv', '.dll') + self.copy_binary(build_dir, dest_dir, 'sqlsrv', '.pdb') + self.copy_binary(build_dir, dest_dir, 'pdo_sqlsrv', '.dll') + self.copy_binary(build_dir, dest_dir, 'pdo_sqlsrv', '.pdb') + else: + self.copy_binary(build_dir, dest_dir, self.driver, '.dll') + self.copy_binary(build_dir, dest_dir, self.driver, '.pdb') + From bdad16e904dc7c0481f29c7e9b49b4d83cefdd6c Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 08:54:21 -0700 Subject: [PATCH 57/87] modified comments and corrected typo --- buildscripts/builddrivers.py | 20 ++++++++++++-------- buildscripts/buildtools.py | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 03b0c9f6..0bb771b0 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -31,11 +31,7 @@ class BuildDriver(object): """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: Attributes: - phpver # PHP version, e.g. 7.1.*, 7.2.* etc. - driver # all, sqlsrv, or pdo_sqlsrv - arch # x64 or x86 - thread # nts or ts - debug # whether debug is enabled + util # BuildUtil object whose constructor takes phpver, driver, arch, thread, debug repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not @@ -65,10 +61,14 @@ class BuildDriver(object): print('Debug enabled: ', self.util.debug_enabled) def clean_or_remove(self, root_dir, work_dir): - """Check if php source directory already exists. If so, prompt user whether to rebuild, clean, or superclean, meaning to remove the entire php source directory.""" + """Check if php source directory already exists. + If so, prompt user whether to rebuild, clean, or superclean, + meaning to remove the entire php source directory. + """ phpsrc = self.util.phpsrc_root(root_dir) if os.path.exists( phpsrc ): - print(phpsrc + " exists.") + print(phpsrc + " exists.") + print("Choose rebuild(r) if using the same configuration. Choose clean(c) otherwise. If unsure, choose superclean(s).") choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") self.make_clean = False if choice == 'r': @@ -86,7 +86,11 @@ class BuildDriver(object): os.chdir(work_dir) def build_extensions(self, dest, logfile): - """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations.""" + """This takes care of getting the drivers' source files, building the drivers. + If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. + In this case, remote_path must be defined such that the binaries will be copied + to the designated destinations. + """ work_dir = os.path.dirname(os.path.realpath(__file__)) if self.download_source: diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 17f2d4a9..6633371a 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -189,7 +189,9 @@ class BuildUtil(object): @staticmethod def download_msphpsql_source(repo, branch, dest_folder = 'Source', clean_up = True): - """Download to *dest_folder* the msphpsql archive of the specified GitHub *repo* and *branch*.""" + """Download to *dest_folder* the msphpsql archive of the specified + GitHub *repo* and *branch*. The downloaded files will be removed by default. + """ try: work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -207,8 +209,8 @@ class BuildUtil(object): with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file: shutil.copyfileobj(response, out_file) except: - print ("Resort to skip ssl verifcation...") - # need to skip ssl verifcation on some agents + print ("Resort to skip ssl verification...") + # need to skip ssl verification on some agents # see https://www.python.org/dev/peps/pep-0476/ with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as response, open(file, 'wb') as out_file: shutil.copyfileobj(response, out_file) @@ -234,7 +236,9 @@ class BuildUtil(object): raise def update_driver_source(self, source_dir, driver): - """Update the *driver* source in *source_path* with the latest version, file descriptions, etc.""" + """Update the *driver* source in *source_path* with the + latest version, file descriptions, etc. + """ driver_dir = os.path.join(source_dir, driver) # Update Template.rc @@ -327,7 +331,10 @@ class BuildUtil(object): print('Cannot create ', filename) def build_drivers(self, make_clean = False, dest = None, log_file = None): - """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder exists in the working directory, and this folder will be removed when the build is complete.""" + """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder + exists in the working directory, and this folder will be removed when the build + is complete. + """ work_dir = os.path.dirname(os.path.realpath(__file__)) # First, update the driver source file contents @@ -376,7 +383,7 @@ class BuildUtil(object): os.system(starter_script + ' -t ' + batch_file) # Now we can safely remove the Source folder, because its contents have - # already been modified when building the extensions + # already been modified prior to building the extensions shutil.rmtree(os.path.join(phpSDK, 'Source'), ignore_errors=True) # Next, rename the newly compiled PHP extensions @@ -393,7 +400,9 @@ class BuildUtil(object): os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries based on PHP version and thread, including pdb files.""" + """Rename the sqlsrv and/or pdo_sqlsrv binaries based on + PHP version and thread, including pdb files. + """ # Derive the path to where the extensions are located ext_dir = self.build_abs_path(sdk_dir) @@ -414,7 +423,9 @@ class BuildUtil(object): shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, to the right place.""" + """Copy the sqlsrv and/or pdo_sqlsrv binaries, + including pdb files, to the right place. + """ build_dir = self.build_abs_path(sdk_dir) print('Copying the binaries from', build_dir) if copy_to_ext: From 2b2de0c2720839ae50ff45404297ec0db18fe27a Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 09:21:36 -0700 Subject: [PATCH 58/87] added more checks for path existence --- buildscripts/builddrivers.py | 13 ++++++++----- buildscripts/buildtools.py | 8 +++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 0bb771b0..b429e14a 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -105,13 +105,16 @@ class BuildDriver(object): source = input("Hit ENTER to reuse '" + self.source_path + "' or provide another path to the Source folder: ") if len(source) == 0: source = self.source_path - - if os.path.exists( source ): + + valid = True + if os.path.exists(source) and os.path.exists(os.path.join(source, 'shared')): + # Checking the existence of 'shared' folder only, assuming + # sqlsrv and/or pdo_sqlsrv are also present if it exists self.source_path = source break - else: - print('The path provided does not exist. Please re-enter.') - + + print("The path provided is invalid. Please re-enter.") + print('Copying source files from', source) os.system('ROBOCOPY ' + source + '\shared ' + work_dir + '\Source\shared /xx /xo ') diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 6633371a..1436f981 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -111,9 +111,15 @@ class BuildUtil(object): shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) def remove_prev_build(self, sdk_dir): - """Remove all binaries and source code in the Release* or Debug* folders""" + """Remove all binaries and source code in the + Release* or Debug* folders according to the current + configuration + """ print('Removing previous build...') build_dir = self.build_abs_path(sdk_dir) + if not os.path.exists(build_dir): + return + os.chdir(build_dir) os.system('DEL *sqlsrv*') From 9b5743d685f36907d6135c6c9e5e47bc1bc31a8d Mon Sep 17 00:00:00 2001 From: Hadis-Fard Date: Mon, 14 Aug 2017 14:54:58 -0700 Subject: [PATCH 59/87] updated per #474 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0756cdc7..6c9c2aeb 100644 --- a/README.md +++ b/README.md @@ -250,8 +250,8 @@ On Ubuntu and Debian systems only, run: On all systems, run: - sudo pecl install sqlsrv - sudo pecl install pdo_sqlsrv + pecl install sqlsrv + pecl install pdo_sqlsrv ### Step 4: Install and Configure Apache From 99ccc281462af7c9886714b9f9dcd5a519edd515 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 14:58:37 -0700 Subject: [PATCH 60/87] Added code to remove optimization flags for debug build --- buildscripts/builddrivers.py | 38 +++++++++++++++++++++++++----------- buildscripts/buildtools.py | 29 ++++++++++++++++++--------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index b429e14a..a27cf6dc 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -35,7 +35,7 @@ class BuildDriver(object): repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not - package # package name for the binaries + package # package name for the binaries (will be ignored for local builds) remote_path # remote destination to where the drivers will be placed (None for local builds) local # whether the build is local source_path # path to a local source folder @@ -54,42 +54,55 @@ class BuildDriver(object): self.source_path = None # None initially but will be set later if not downloading from GitHub def show_config(self): + print() print('PHP Version: ', self.util.phpver) print('Arch: ', self.util.arch) print('Thread: ', self.util.thread) print('Driver: ', self.util.driver) print('Debug enabled: ', self.util.debug_enabled) + print() def clean_or_remove(self, root_dir, work_dir): - """Check if php source directory already exists. - If so, prompt user whether to rebuild, clean, or superclean, - meaning to remove the entire php source directory. + """Only check this when building locally and not rebuilding. If the php source directory + already exists, this will prompt user whether to rebuild, clean, or superclean, the last option + will remove the entire php source directory. + + :param root_dir: the C:\ drive + :param work_dir: the directory of this script + :outcome: the old binaries, if exist, will be removed """ phpsrc = self.util.phpsrc_root(root_dir) if os.path.exists( phpsrc ): print(phpsrc + " exists.") print("Choose rebuild(r) if using the same configuration. Choose clean(c) otherwise. If unsure, choose superclean(s).") - choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") + build_choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") self.make_clean = False - if choice == 'r': + if build_choice == 'r': print('Will rebuild the binaries') + # only the old binaries based on the current configuration will be removed self.util.remove_prev_build(root_dir) - elif choice == 'c': + elif build_choice == 'c': print('Will make clean') self.make_clean = True - # this step is necessary in case the user has changed the configuration + # all old builds are removed, and this step is necessary because + # the user might have changed the configuration self.util.remove_old_builds(root_dir) else: print('Will remove ' + phpsrc) os.system('RMDIR /s /q ' + phpsrc) - os.chdir(work_dir) + os.chdir(work_dir) # change back to the working directory def build_extensions(self, dest, logfile): """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations. + + :param dest: either None (for remote builds) or the C:\ drive (for local builds) + :param logfile: the name of the logfile + :outcome: the drivers and symbols will renamed and placed in the appropriate location(s) + """ work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -98,6 +111,7 @@ class BuildDriver(object): self.util.download_msphpsql_source(repo, branch) else: # This case only happens when building locally (interactive mode) + # because download_source must be True for remote builds while True: if self.source_path is None: source = input('Enter the full path to the Source folder: ') @@ -153,7 +167,9 @@ class BuildDriver(object): def build(self): - """This is the main entry point of building drivers for PHP.""" + """This is the main entry point of building drivers for PHP. + For local builds, this will loop till the user decides to quit. + """ self.show_config() work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -221,7 +237,7 @@ if __name__ == '__main__': parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") - parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers") + parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers (do not use this when building locally)") args = parser.parse_args() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 1436f981..9b749ac0 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -111,9 +111,8 @@ class BuildUtil(object): shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) def remove_prev_build(self, sdk_dir): - """Remove all binaries and source code in the - Release* or Debug* folders according to the current - configuration + """Remove all binaries and source code in the Release* or Debug* + folders according to the current configuration """ print('Removing previous build...') build_dir = self.build_abs_path(sdk_dir) @@ -244,9 +243,20 @@ class BuildUtil(object): def update_driver_source(self, source_dir, driver): """Update the *driver* source in *source_path* with the latest version, file descriptions, etc. + If debug is enabled, will remove the optimization flag """ driver_dir = os.path.join(source_dir, driver) + if self.debug_enabled: + # Remove the optimization flag in the config file for this driver + # because '/O2' option is incompatible with Debug mode + print('Removing optimization flag for', driver) + config_file = os.path.join(driver_dir, 'config.w32') + if driver == 'sqlsrv': + self.update_file_content(config_file, 'ADD_FLAG( "CFLAGS_SQLSRV", "/O2" );', '') + elif driver == 'pdo_sqlsrv': + self.update_file_content(config_file, 'ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/O2" );', '') + # Update Template.rc template_file = os.path.join(driver_dir, 'template.rc') if driver == 'sqlsrv': @@ -399,15 +409,15 @@ class BuildUtil(object): self.copy_binaries(sdk_dir, copy_to_ext) def rename_binary(self, path, driver, suffix): - """Rename sqlsrv or pdo_sqlsrv binary.""" + """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) based on the *suffix*.""" driver_old_name = self.driver_name(driver, suffix) driver_new_name = self.driver_new_name(driver, suffix) os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries based on - PHP version and thread, including pdb files. + """Rename the sqlsrv and/or pdo_sqlsrv binaries according to the + PHP version and thread, including pdb files (the symbols). """ # Derive the path to where the extensions are located @@ -424,13 +434,14 @@ class BuildUtil(object): self.rename_binary(ext_dir, self.driver, '.pdb') def copy_binary(self, from_dir, dest_dir, driver, suffix): - """Copy sqlsrv or pdo_sqlsrv binary to *dest_dir*.""" + """Copy sqlsrv or pdo_sqlsrv binary (based on *suffix*) to *dest_dir*.""" binary = self.driver_new_name(driver, suffix) shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, - including pdb files, to the right place. + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, + to the right place, depending on *copy_to_ext*. The default is to + copy them to the 'ext' folder. """ build_dir = self.build_abs_path(sdk_dir) print('Copying the binaries from', build_dir) From 1b3e0279683596d123243d419ee0e537055939d4 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 09:50:34 -0700 Subject: [PATCH 61/87] Modified scripts based on review comments --- buildscripts/builddrivers.py | 28 ++++++++++++---------------- buildscripts/buildtools.py | 6 +++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index a27cf6dc..fbd663a3 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -1,10 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/python3 ######################################################################################### # # Description: This script helps to build drivers in a Windows environment for PHP 7+ (32-bit/64-bit) # # Requirement: -# python 3.4 +# python 3.x # PHP SDK and PHP Source # Driver source code folder / GitHub repository # Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) @@ -35,18 +35,18 @@ class BuildDriver(object): repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not - package # package name for the binaries (will be ignored for local builds) remote_path # remote destination to where the drivers will be placed (None for local builds) - local # whether the build is local + local # a boolean flag - whether the build is local + rebuild # a boolean flag - whether the user is rebuilding + make_clean # a boolean flag - whether make clean is necessary source_path # path to a local source folder """ - def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, package, path): + def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, path): self.util = BuildUtil(phpver, driver, arch, thread, debug) self.repo = repo self.branch = branch self.download_source = download - self.package = package self.remote_path = path self.local = path is None # the default path is None, which means running locally self.rebuild = False @@ -147,8 +147,7 @@ class BuildDriver(object): if self.remote_path is None: print('Errors: Drivers destination should be defined! Do nothing.') else: - OS_folder = "Windows" # hardcode this since this script is only run in Windows - dest_drivers = os.path.join(self.remote_path, 'PHP', 'Drivers', self.package, OS_folder, self.util.major_version(), self.util.arch) + dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) dest_symbols = os.path.join(dest_drivers, 'Symbols') # All intermediate directories will be created in order to create the leaf directory @@ -236,8 +235,7 @@ if __name__ == '__main__': parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository") parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") - parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") - parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers (do not use this when building locally)") + parser.add_argument('-p', '--DESTPATH', default=None, help="the remote destination for the drivers (do not use this for local builds)") args = parser.parse_args() @@ -249,19 +247,18 @@ if __name__ == '__main__': repo = args.REPO branch = args.BRANCH download = args.GITHUB.lower() == 'yes' - path = args.PATH - package = args.PACKAGE + path = args.DESTPATH if phpver is None: # assuming it is building drivers locally when required to prompt # thus will not prompt for drivers' destination path, which is None by default phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") - arch_version = input("Want to build 64-bit [y/n]: ") + arch_version = input("64-bit? [y/n]: ") thread = validate_input("Thread safe? ", "nts/ts") driver = validate_input("Driver to build? ", "all/sqlsrv/pdo_sqlsrv") - debug_mode = input("Want to build debug [y/n]? ") + debug_mode = input("Debug enabled? [y/n]: ") - answer = input("Download source from a GitHub repo [y/n]? ") + answer = input("Download source from a GitHub repo? [y/n]: ") download = False if answer == 'yes' or answer == 'y' or answer == '': download = True @@ -286,6 +283,5 @@ if __name__ == '__main__': repo, branch, download, - package, path) builder.build() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 9b749ac0..61c0496a 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -1,11 +1,11 @@ -#!/usr/bin/python +#!/usr/bin/python3 ######################################################################################### # # Description: The class BuildUtil will build Microsoft SQL Server PHP 7+ Drivers # for 32 bit and 64 bit. # # Requirement: -# python 3.4 +# python 3.x # PHP SDK and PHP Source # Driver source code folder # Git for Windows @@ -48,7 +48,7 @@ class BuildUtil(object): """Return the version label based on the PHP version.""" major_ver = self.major_version() - if major_ver == '7.0': + if major_ver[2] == '0': version = major_ver[0] else: version = major_ver[0] + major_ver[2] From 8831ce3fa8bb91bd9404c9a819abb34bbcebcfae Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 15 Aug 2017 10:54:41 -0700 Subject: [PATCH 62/87] Added instructions for SUSE install --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0756cdc7..b3025d7f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Thank you for taking time to take our February survey. Let us know how we are do * [**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) +* [**SUSE + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/sles) * [**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/) @@ -80,7 +81,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, Debian 8, and Mac OS X. +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, SUSE 12, and Mac OS X. ### Step 1: Install PHP7+ @@ -120,6 +121,12 @@ The following instructions assume a clean environment and show how to install PH apt-get update apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml +**SUSE 12** + + sudo su + zypper refresh + zypper install -y php7 php7-pear php7-devel + **Mac OS X** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -163,6 +170,13 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. apt-get update apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml +**SUSE 12** + + sudo su + zypper -n ar -f http://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_42.3/ devel:languages:php + zypper --gpg-auto-import-keys refresh + zypper -n install php7 php7-pear php7-devel + **Mac OS X** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -230,6 +244,19 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. sudo ACCEPT_EULA=Y apt-get install msodbcsql sudo apt-get install unixodbc-dev +**SUSE 12** + + sudo su + zypper ar https://packages.microsoft.com/config/sles/12/prod.repo + sudo zypper --gpg-auto-import-keys refresh + exit + sudo ACCEPT_EULA=Y zypper install msodbcsql + sudo ACCEPT_EULA=Y zypper install mssql-tools + sudo zypper install unixODBC-devel + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + **Mac OS X** brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release @@ -244,7 +271,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. *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: +On Ubuntu, Debian, and SUSE systems only, run: sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system @@ -274,6 +301,14 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini +**SUSE** + + sudo su + zypper install apache2 apache2-mod_php7 + a2enmod php7 + echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini + **Mac OS X** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -297,6 +332,14 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini +**SUSE** + + sudo su + zypper install apache2 apache2-mod_php7 + a2enmod php7 + echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini + **Mac OS X** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -304,7 +347,7 @@ On all systems, run: ### Step 5: Restart Apache to load the new php.ini file -**Ubuntu and Debian** +**Ubuntu, Debian, and SUSE** sudo systemctl restart apache2 @@ -322,7 +365,7 @@ Note: On RedHat, SELinux is installed by default and runs in Enforcing mode. To ### 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. +Navigate to your system's document root -- `/var/www/html` on Ubuntu, Debian, and Redhat, `/srv/www/htdocs` on SUSE, or `/usr/local/var/www/htdocs` on Mac. 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: Tue, 15 Aug 2017 11:54:51 -0700 Subject: [PATCH 63/87] added a new README plus modifying the project README --- README.md | 26 ++++++++++++++++---------- buildscripts/builddrivers.py | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0756cdc7..dff3fda4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Thank you for taking time to take our February survey. Let us know how we are do ## Announcements - Please visit the [blog][blog] for more announcements. +Please visit the [blog][blog] for more announcements. ## Build (Windows) @@ -46,23 +46,29 @@ Note: if you prefer, you can use the pre-compiled binary found [HERE](https://gi #### 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. +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. +1. Download the source code directory from this repository -2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. +2. Make a copy of *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder -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` +3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder into the PHP source ext subdirectory. -4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. +4. Run `buildconf --force` to rebuild the configure.js script to include the driver. -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. +5. 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 --with-pdo-sqlsrv=shared` -This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. +6. Run `nmake`. Optionally, you can run `nmake clean` first. + +7. 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. + +The extensions have been compiled and tested with the PHP 7.0.* and 7.1.* using the Visual C++ 2015 compiler as well as PHP 7.2.0 beta using the Visual C++ 2017 V15.0. + +For an example of how to automate building the Microsoft Drivers for PHP for SQL Server, please browse the *buildscripts* directory. ## Install (Windows) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index fbd663a3..a67af601 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -145,7 +145,7 @@ class BuildDriver(object): # Make sure drivers path is defined if self.remote_path is None: - print('Errors: Drivers destination should be defined! Do nothing.') + print('Errors: Drivers destination should be defined! Doing nothing.') else: dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) dest_symbols = os.path.join(dest_drivers, 'Symbols') From d07c454dc9ba418731abd7ea115da1b976b1b7d9 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 13:20:20 -0700 Subject: [PATCH 64/87] README for build scripts --- buildscripts/README.md | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 buildscripts/README.md diff --git a/buildscripts/README.md b/buildscripts/README.md new file mode 100644 index 00000000..ffe79f26 --- /dev/null +++ b/buildscripts/README.md @@ -0,0 +1,56 @@ +## Windows + +### Prerequisites +To use the Python build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x. + +To build extensions for PHP 7.0* or 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. + +For PHP 7.2*, install Visual Studio 2017, and make sure Visual C++ toolset, the Windows SDK components, and Git for Windows are installed. + +See [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for more details. + +### Build PHP extensions + +Launch a regular `cmd` prompt and change to the directory where these Python scripts are. + +You'll be asked to input the PHP version. Simply type the version number like `7.1.7`. + +If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit https://github.com/php/php-src to find the appropriate tag names. + +**Use Interactive mode** + +Run `py builddrivers.py` + +Most questions are self-explanatory. Use lower cases for your inputs, and you can simply hit `ENTER` key for `yes/no` questions. + +When given a choice whether to download from a GitHub repository, you can choose to provide the full path to your local Source folder instead. + +**Use Command-line arguments** + +Run `py builddrivers.py` with command line arguments. For example: + +`py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` + +or + +`py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` + +**Notes** + +It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. + +If this is not the first time you build the drivers for a PHP version with certain configuration options (such as arch, thread safe, etc.), you will be prompted whether to rebuild, clean or superclean. Choose `rebuild` if you have always used the same configuration. Otherwise, choose `clean` to remove previous builds (binaries). The last option will remove the entire `php--src` directory, which is often unnecessary. + +When something goes wrong during the build, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. + +After the compilation is complete, you will be given the option to rebuild or quit. If you choose rebuild, the extensions will be re-compiled (say after you have changed any source or header file). This script will keep running until you choose to quit. + +In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. + +When running build unattended, you should specify the destination path `--DESTPATH=`. In such case, the `php-sdk` folder will be created in the same working directory of these build scripts, and the drivers will be copied to your designated path. The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. + + + + + + From ad970b4b3a59bf1aee1b3173f23c998a50cab221 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 16:15:59 -0700 Subject: [PATCH 65/87] updated update_file_content as per review comment --- buildscripts/buildtools.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 61c0496a..32423d37 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -21,6 +21,7 @@ import stat import datetime import urllib.request import zipfile +import fileinput class BuildUtil(object): """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: @@ -141,12 +142,9 @@ class BuildUtil(object): def update_file_content(file, search_str, new_str): """Find *search_str* and replace it by *new_str* in a *file*""" os.chmod(file, stat.S_IWRITE) - f = open(file, 'r') - filedata = f.read() - updatedata = filedata.replace(search_str, new_str) - f = open(file, 'w') - f.write(updatedata) - f.close() + with fileinput.FileInput(file, inplace=True) as f: + for line in f: + print(line.replace(search_str, new_str), end='') @staticmethod def generateMMDD(): @@ -390,6 +388,12 @@ class BuildUtil(object): # Copy the generated batch file to phpSDK for the php starter script shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + sdk_source = os.path.join(phpSDK, 'Source') + # Sometimes, for various reasons, the Source folder from previous build + # might exist in phpSDK. If so, remove it first + if os.path.exists(sdk_source): + os.chmod(sdk_source, stat.S_IWRITE) + shutil.rmtree(sdk_source, ignore_errors=True) shutil.move(source_dir, phpSDK) # Invoke phpsdk--.bat From ff9ef9e008dd8db092c0ff2c11894a8bcdc6ab78 Mon Sep 17 00:00:00 2001 From: David Puglielli Date: Tue, 15 Aug 2017 18:53:37 -0700 Subject: [PATCH 66/87] changed OS X to macOS --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b3025d7f..947a4102 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,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, Debian 8, SUSE 12, and Mac OS X. +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, SUSE 12, and macOS. ### Step 1: Install PHP7+ @@ -127,7 +127,7 @@ The following instructions assume a clean environment and show how to install PH zypper refresh zypper install -y php7 php7-pear php7-devel -**Mac OS X** +**macOS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -177,7 +177,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. zypper --gpg-auto-import-keys refresh zypper -n install php7 php7-pear php7-devel -**Mac OS X** +**macOS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -257,7 +257,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc -**Mac OS X** +**macOS** brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release brew update @@ -309,7 +309,7 @@ On all systems, run: echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini -**Mac OS X** +**macOS** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -340,7 +340,7 @@ On all systems, run: echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini -**Mac OS X** +**macOS** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -359,7 +359,7 @@ Note: On RedHat, SELinux is installed by default and runs in Enforcing mode. To sudo setsebool -P httpd_can_network_connect_db 1 -**Mac OS X** +**macOS** sudo apachectl restart From 6f14e0f6d9c1300a685cfbf8c225bfdd85befc13 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 09:19:27 -0700 Subject: [PATCH 67/87] No longer renamed the pdb files --- buildscripts/builddrivers.py | 2 +- buildscripts/buildtools.py | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index a67af601..4005cbbf 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -148,7 +148,7 @@ class BuildDriver(object): print('Errors: Drivers destination should be defined! Doing nothing.') else: dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) - dest_symbols = os.path.join(dest_drivers, 'Symbols') + dest_symbols = os.path.join(dest_drivers, 'Symbols', self.util.thread) # All intermediate directories will be created in order to create the leaf directory if os.path.exists(dest_symbols) == False: diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 32423d37..0875398f 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -386,8 +386,12 @@ class BuildUtil(object): os.chdir(phpSDK) os.system('git pull ') - # Copy the generated batch file to phpSDK for the php starter script - shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + # Move the generated batch file to phpSDK for the php starter script + sdk_batch_file = os.path.join(phpSDK, batch_file) + if os.path.exists(sdk_batch_file): + os.remove(sdk_batch_file) + shutil.move(os.path.join(work_dir, batch_file), phpSDK) + sdk_source = os.path.join(phpSDK, 'Source') # Sometimes, for various reasons, the Source folder from previous build # might exist in phpSDK. If so, remove it first @@ -412,16 +416,16 @@ class BuildUtil(object): # Final step, copy the binaries to the right place self.copy_binaries(sdk_dir, copy_to_ext) - def rename_binary(self, path, driver, suffix): - """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) based on the *suffix*.""" - driver_old_name = self.driver_name(driver, suffix) - driver_new_name = self.driver_new_name(driver, suffix) + def rename_binary(self, path, driver): + """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) (only the dlls).""" + driver_old_name = self.driver_name(driver, '.dll') + driver_new_name = self.driver_new_name(driver, '.dll') os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries according to the - PHP version and thread, including pdb files (the symbols). + """Rename the sqlsrv and/or pdo_sqlsrv dlls according to the PHP + version and thread. """ # Derive the path to where the extensions are located @@ -429,21 +433,21 @@ class BuildUtil(object): print("Renaming binaries in ", ext_dir) if self.driver == 'all': - self.rename_binary(ext_dir, 'sqlsrv', '.dll') - self.rename_binary(ext_dir, 'sqlsrv', '.pdb') - self.rename_binary(ext_dir, 'pdo_sqlsrv', '.dll') - self.rename_binary(ext_dir, 'pdo_sqlsrv', '.pdb') + self.rename_binary(ext_dir, 'sqlsrv') + self.rename_binary(ext_dir, 'pdo_sqlsrv') else: - self.rename_binary(ext_dir, self.driver, '.dll') - self.rename_binary(ext_dir, self.driver, '.pdb') + self.rename_binary(ext_dir, self.driver) def copy_binary(self, from_dir, dest_dir, driver, suffix): """Copy sqlsrv or pdo_sqlsrv binary (based on *suffix*) to *dest_dir*.""" - binary = self.driver_new_name(driver, suffix) + if suffix == '.dll': + binary = self.driver_new_name(driver, suffix) + else: + binary = self.driver_name(driver, suffix) shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including the pdb files, to the right place, depending on *copy_to_ext*. The default is to copy them to the 'ext' folder. """ From eda3b7f35883eb747208a39ff45dc77019b2a8e1 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 13:04:26 -0700 Subject: [PATCH 68/87] Modified README files and removed odbc requirement to build --- README.md | 42 ++++------------- buildscripts/README.md | 93 ++++++++++++++++++++++++++++---------- buildscripts/buildtools.py | 2 +- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index dff3fda4..f77984ec 100644 --- a/README.md +++ b/README.md @@ -42,33 +42,9 @@ 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) +If you prefer, you can use the pre-compiled binaries 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. Download the source code directory from this repository - -2. Make a copy of *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder - -3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder into the PHP source ext subdirectory. - -4. Run `buildconf --force` to rebuild the configure.js script to include the driver. - -5. 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 --with-pdo-sqlsrv=shared` - -6. Run `nmake`. Optionally, you can run `nmake clean` first. - -7. 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. - -The extensions have been compiled and tested with the PHP 7.0.* and 7.1.* using the Visual C++ 2015 compiler as well as PHP 7.2.0 beta using the Visual C++ 2017 V15.0. - -For an example of how to automate building the Microsoft Drivers for PHP for SQL Server, please browse the *buildscripts* directory. +The *buildscripts* directory contains step by step instructions on how to build the Microsoft Drivers for PHP for SQL Server. You can either build manually or use the sample scripts provided, which help automate the process. ## Install (Windows) @@ -86,7 +62,7 @@ For an example of how to automate building the Microsoft Drivers for PHP for SQL 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. +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. ### Step 1: Install PHP7+ @@ -126,7 +102,7 @@ The following instructions assume a clean environment and show how to install PH apt-get update apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml -**Mac OS X** +**Mac OS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -169,7 +145,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. apt-get update apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml -**Mac OS X** +**Mac OS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -236,7 +212,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. sudo ACCEPT_EULA=Y apt-get install msodbcsql sudo apt-get install unixodbc-dev -**Mac OS X** +**Mac OS** brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release brew update @@ -280,7 +256,7 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini -**Mac OS X** +**Mac OS** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -303,7 +279,7 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini -**Mac OS X** +**Mac OS** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -322,7 +298,7 @@ Note: On RedHat, SELinux is installed by default and runs in Enforcing mode. To sudo setsebool -P httpd_can_network_connect_db 1 -**Mac OS X** +**Mac OS** sudo apachectl restart diff --git a/buildscripts/README.md b/buildscripts/README.md index ffe79f26..da71851d 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -1,53 +1,96 @@ -## Windows +# Windows -### Prerequisites -To use the Python build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x. +## Prerequisites -To build extensions for PHP 7.0* or 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. +To build extensions for + * PHP 7.0* or PHP 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. + * PHP 7.2*, install Visual Studio 2017, including Visual C++ toolset, the Windows SDK components, and Git for Windows. -For PHP 7.2*, install Visual Studio 2017, and make sure Visual C++ toolset, the Windows SDK components, and Git for Windows are installed. +To use the sample build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x in Windows. -See [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for more details. +## Compile the drivers -### Build PHP extensions +You must first be able to build PHP 7.* without including these extensions. For help with doing this, see the [official PHP website](https://wiki.php.net/internals/windows/stepbystepbuild) for building PHP 7.0* or PHP 7.1* on Windows or [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for the new instructions for building PHP 7.2 and/or above. -Launch a regular `cmd` prompt and change to the directory where these Python scripts are. +The Microsoft Drivers for PHP for SQL Server have been compiled and tested with PHP 7.0.* and 7.1.* using the Visual C++ 2015 as well as PHP 7.2.0 beta using the Visual C++ 2017 v15.0. -You'll be asked to input the PHP version. Simply type the version number like `7.1.7`. +### Manually building from source -If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit https://github.com/php/php-src to find the appropriate tag names. +1. Download the *source* directory from this repository -**Use Interactive mode** +2. Make a copy of the *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder -Run `py builddrivers.py` +3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder(s) into the PHP source ext subdirectory -Most questions are self-explanatory. Use lower cases for your inputs, and you can simply hit `ENTER` key for `yes/no` questions. +4. Run `buildconf --force` to rebuild the configure.js script to include the *sqlsrv* and/or *pdo_sqlsrv* driver(s). -When given a choice whether to download from a GitHub repository, you can choose to provide the full path to your local Source folder instead. +5. Run `configure.bat` with the desired driver options (as shown below) to generate the makefile. You can run `configure.bat --help` to see what other options are available. For example, for non-thread safe build, add this option `--disable-zts`. + * For SQLSRV add: `--enable-sqlsrv=shared` + * For PDO_SQLSRV add: `--enable-pdo --with-pdo-sqlsrv=shared` -**Use Command-line arguments** +6. Run `nmake`. Optionally, you can run `nmake clean` first. -Run `py builddrivers.py` with command line arguments. For example: +7. To install the drivers, there are two ways: + * Run `nmake install`, or + * Copy the drivers: + * Find the directory where the newly compiled `php.exe` is + * Locate the compiled php_sqlsrv.dll and/or php_pdo_sqlsrv.dll + * Copy the dll(s) to the `ext` subfolder -`py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` +### Using the sample build scripts -or +The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to build our extensions for PHP in Windows. -`py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` +#### Overview -**Notes** +When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. +It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. -If this is not the first time you build the drivers for a PHP version with certain configuration options (such as arch, thread safe, etc.), you will be prompted whether to rebuild, clean or superclean. Choose `rebuild` if you have always used the same configuration. Otherwise, choose `clean` to remove previous builds (binaries). The last option will remove the entire `php--src` directory, which is often unnecessary. +#### Steps + +1. Launch a regular `cmd` prompt + +2. Change to the directory where the Python scripts `builddrivers.py` and `buildtools.py` are + +3. Interactive mode: + * Run `py builddrivers.py` to use the interactive mode. Use lower cases to answer the following questions: + * PHP Version (i.e. the version number like `7.1.7` or `7.2.0beta2`) + * 64-bit? + * Thread safe? + * Driver? + * Debug enabled? + * Download source from GitHub? + * For `yes/no` questions, you can simply hit `ENTER` key for `yes`. Other questions are self-explanatory. + +4. Use Command-line arguments + * Run `py builddrivers.py -h` to get a list of options and their descriptions + * For example, + * `py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` + * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` + +5. If the script detects the presence of a PHP source directory, you will be prompted whether to rebuild, clean or superclean. Choose + * `rebuild` if you have always used the same configuration (32 bit, thread safe, etc.) + * `clean` to remove previous builds (binaries) + * `superclean` to remove the entire `php--src` directory, which is often unnecessary + +6. If you choose not to download from a GitHub repository, you will be asked to provide the full path to your local Source folder. + +7. If the compilation is successful, you will be given the option to rebuild or quit. + +#### Troubleshooting When something goes wrong during the build, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. -After the compilation is complete, you will be given the option to rebuild or quit. If you choose rebuild, the extensions will be re-compiled (say after you have changed any source or header file). This script will keep running until you choose to quit. - In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. -When running build unattended, you should specify the destination path `--DESTPATH=`. In such case, the `php-sdk` folder will be created in the same working directory of these build scripts, and the drivers will be copied to your designated path. The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. +#### Building the extensions unattended + +You can invoke `py builddrivers.py` with the desired options plus the destination path `--DESTPATH=`. + +In such case, the `php-sdk` folder will be created in the same directory of these build scripts. Note that the PHP drivers will also be copied to the designated path. + +The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 0875398f..d527febb 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -296,7 +296,7 @@ class BuildUtil(object): else: # pdo_sqlsrv cmd_line = ' --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line - cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi' + cmd_line + ' --disable-ipv6 --with-odbcver=0x0380 --enable-embed' + cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi --enable-embed' + cmd_line if self.thread == 'nts': cmd_line = cmd_line + ' --disable-zts' return cmd_line From da43f6b58c3bef8e81f3c56c77268bbc430d2d8b Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 11 Aug 2017 12:49:54 -0700 Subject: [PATCH 69/87] Python scripts for building extensions for PHP 7+ in Windows --- buildscripts/builddrivers.py | 268 +++++++++++++++++++++ buildscripts/buildtools.py | 437 +++++++++++++++++++++++++++++++++++ 2 files changed, 705 insertions(+) create mode 100644 buildscripts/builddrivers.py create mode 100644 buildscripts/buildtools.py diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py new file mode 100644 index 00000000..03b0c9f6 --- /dev/null +++ b/buildscripts/builddrivers.py @@ -0,0 +1,268 @@ +#!/usr/bin/python +######################################################################################### +# +# Description: This script helps to build drivers in a Windows environment for PHP 7+ (32-bit/64-bit) +# +# Requirement: +# python 3.4 +# PHP SDK and PHP Source +# Driver source code folder / GitHub repository +# Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) +# +# Execution: Run with command line with required options. +# Examples: +# py builddrivers.py (for interactive mode) +# py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no +# py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=all --GITHUB=yes +# +# Output: Build the drivers using PHP SDK. When running locally, if build is unsuccessful, +# the log file will be launched for examination. Otherwise, the drivers will be renamed +# and copied to the designated location(s). +# +############################################################################################# + +import sys +import shutil +import os.path +import argparse +from buildtools import BuildUtil + +class BuildDriver(object): + """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: + + Attributes: + phpver # PHP version, e.g. 7.1.*, 7.2.* etc. + driver # all, sqlsrv, or pdo_sqlsrv + arch # x64 or x86 + thread # nts or ts + debug # whether debug is enabled + repo # GitHub repository + branch # GitHub repository branch + download_source # download source from GitHub or not + package # package name for the binaries + remote_path # remote destination to where the drivers will be placed (None for local builds) + local # whether the build is local + source_path # path to a local source folder + """ + + def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, package, path): + self.util = BuildUtil(phpver, driver, arch, thread, debug) + self.repo = repo + self.branch = branch + self.download_source = download + self.package = package + self.remote_path = path + self.local = path is None # the default path is None, which means running locally + self.rebuild = False + self.make_clean = False + self.source_path = None # None initially but will be set later if not downloading from GitHub + + def show_config(self): + print('PHP Version: ', self.util.phpver) + print('Arch: ', self.util.arch) + print('Thread: ', self.util.thread) + print('Driver: ', self.util.driver) + print('Debug enabled: ', self.util.debug_enabled) + + def clean_or_remove(self, root_dir, work_dir): + """Check if php source directory already exists. If so, prompt user whether to rebuild, clean, or superclean, meaning to remove the entire php source directory.""" + phpsrc = self.util.phpsrc_root(root_dir) + if os.path.exists( phpsrc ): + print(phpsrc + " exists.") + choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") + self.make_clean = False + if choice == 'r': + print('Will rebuild the binaries') + self.util.remove_prev_build(root_dir) + elif choice == 'c': + print('Will make clean') + self.make_clean = True + # this step is necessary in case the user has changed the configuration + self.util.remove_old_builds(root_dir) + else: + print('Will remove ' + phpsrc) + os.system('RMDIR /s /q ' + phpsrc) + + os.chdir(work_dir) + + def build_extensions(self, dest, logfile): + """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations.""" + work_dir = os.path.dirname(os.path.realpath(__file__)) + + if self.download_source: + # This will download from the specified branch on GitHub repo and copy the source to the working directory + self.util.download_msphpsql_source(repo, branch) + else: + # This case only happens when building locally (interactive mode) + while True: + if self.source_path is None: + source = input('Enter the full path to the Source folder: ') + else: + source = input("Hit ENTER to reuse '" + self.source_path + "' or provide another path to the Source folder: ") + if len(source) == 0: + source = self.source_path + + if os.path.exists( source ): + self.source_path = source + break + else: + print('The path provided does not exist. Please re-enter.') + + print('Copying source files from', source) + + os.system('ROBOCOPY ' + source + '\shared ' + work_dir + '\Source\shared /xx /xo ') + os.system('ROBOCOPY ' + source + '\sqlsrv ' + work_dir + '\Source\sqlsrv /xx /xo ') + os.system('ROBOCOPY ' + source + '\pdo_sqlsrv ' + work_dir + '\Source\pdo_sqlsrv /xx /xo ') + + print('Start building PHP with the extension...') + + self.util.build_drivers(self.make_clean, dest, logfile) + + if dest is None: + # This indicates the script is NOT running locally, and that + # the drivers should be in the working directory + + # Make sure drivers path is defined + if self.remote_path is None: + print('Errors: Drivers destination should be defined! Do nothing.') + else: + OS_folder = "Windows" # hardcode this since this script is only run in Windows + dest_drivers = os.path.join(self.remote_path, 'PHP', 'Drivers', self.package, OS_folder, self.util.major_version(), self.util.arch) + dest_symbols = os.path.join(dest_drivers, 'Symbols') + + # All intermediate directories will be created in order to create the leaf directory + if os.path.exists(dest_symbols) == False: + os.makedirs(dest_symbols) + + # Now copy all the binaries + if self.util.driver == 'all': + self.util.copy_binary(work_dir, dest_drivers, 'sqlsrv', '.dll') + self.util.copy_binary(work_dir, dest_symbols, 'sqlsrv', '.pdb') + self.util.copy_binary(work_dir, dest_drivers, 'pdo_sqlsrv', '.dll') + self.util.copy_binary(work_dir, dest_symbols, 'pdo_sqlsrv', '.pdb') + else: + self.util.copy_binary(work_dir, dest_drivers, self.util.driver, '.dll') + self.util.copy_binary(work_dir, dest_symbols, self.util.driver, '.pdb') + + + def build(self): + """This is the main entry point of building drivers for PHP.""" + self.show_config() + + work_dir = os.path.dirname(os.path.realpath(__file__)) + root_dir = 'C:' + os.sep + + quit = False + while not quit: + if not self.rebuild and self.local: + self.clean_or_remove(root_dir, work_dir) + + logfile = self.util.get_logfile_name() + + try: + dest = None + if self.local: + dest = root_dir + + self.build_extensions(dest, logfile) + print('Build Completed') + except: + print('Something went wrong. Build incomplete.') + if self.local: # display log file only when building locally + os.startfile(os.path.join(root_dir, 'php-sdk', logfile)) + os.chdir(work_dir) + break + + # Only ask when building locally + if self.local: + choice = input("Rebuild the same configuration(yes) or quit (no) [yes/no]: ") + + if choice.lower() == 'yes' or choice.lower() == 'y' or choice.lower() == '': + print('Rebuilding drivers...') + self.make_clean = False + self.rebuild = True + self.util.remove_prev_build(root_dir) + else: + quit = True + else: + quit = True + + os.chdir(work_dir) + +def validate_input(question, values): + """Return the user selected value, and it must be valid based on *values*.""" + while True: + options = values.split('/') + prompt = '[' + values + ']' + value = input(question + prompt + ': ') + value = value.lower() + if not value in options: + print("An invalid choice is entered. Choose from", prompt) + else: + break + return value + +################################### Main Function ################################### +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('-v', '--PHPVER', help="PHP version, e.g. 7.1.*, 7.2.* etc.") + parser.add_argument('-a', '--ARCH', choices=['x64', 'x86']) + parser.add_argument('-t', '--THREAD', choices=['nts', 'ts']) + parser.add_argument('-d', '--DRIVER', choices=['all', 'sqlsrv', 'pdo_sqlsrv']) + parser.add_argument('-m', '--DEBUG', default='no', choices=['yes', 'no'], help="enable debug mode") + parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository") + parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") + parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") + parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") + parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers") + + args = parser.parse_args() + + phpver = args.PHPVER + arch = args.ARCH + thread = args.THREAD + driver = args.DRIVER + debug = args.DEBUG == 'yes' + repo = args.REPO + branch = args.BRANCH + download = args.GITHUB.lower() == 'yes' + path = args.PATH + package = args.PACKAGE + + if phpver is None: + # assuming it is building drivers locally when required to prompt + # thus will not prompt for drivers' destination path, which is None by default + phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") + arch_version = input("Want to build 64-bit [y/n]: ") + thread = validate_input("Thread safe? ", "nts/ts") + driver = validate_input("Driver to build? ", "all/sqlsrv/pdo_sqlsrv") + debug_mode = input("Want to build debug [y/n]? ") + + answer = input("Download source from a GitHub repo [y/n]? ") + download = False + if answer == 'yes' or answer == 'y' or answer == '': + download = True + repo = input("Name of the repo (hit enter for 'Microsoft'): ") + branch = input("Name of the branch (hit enter for 'dev'): ") + if repo == '': + repo = 'Microsoft' + if branch == '': + branch = 'dev' + + arch_version = arch_version.lower() + arch = 'x64' if arch_version == 'yes' or arch_version == 'y' or arch_version == '' else 'x86' + + debug_mode = debug_mode.lower() + debug = debug_mode == 'yes' or debug_mode == 'y' or debug_mode == '' + + builder = BuildDriver(phpver, + driver, + arch, + thread, + debug, + repo, + branch, + download, + package, + path) + builder.build() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py new file mode 100644 index 00000000..17f2d4a9 --- /dev/null +++ b/buildscripts/buildtools.py @@ -0,0 +1,437 @@ +#!/usr/bin/python +######################################################################################### +# +# Description: The class BuildUtil will build Microsoft SQL Server PHP 7+ Drivers +# for 32 bit and 64 bit. +# +# Requirement: +# python 3.4 +# PHP SDK and PHP Source +# Driver source code folder +# Git for Windows +# Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) +# +# Output: The drivers will be renamed and copied to the specified location. +# +############################################################################################# + +import shutil +import os.path +import stat +import datetime +import urllib.request +import zipfile + +class BuildUtil(object): + """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: + + Attributes: + phpver # PHP version, e.g. 7.1.*, 7.2.* etc. + driver # all, sqlsrv, or pdo_sqlsrv + arch # x64 or x86 + thread # nts or ts + debug_enabled # whether debug is enabled + """ + + def __init__(self, phpver, driver, arch, thread, debug_enabled = False): + self.phpver = phpver + self.driver = driver.lower() + self.arch = arch.lower() + self.thread = thread.lower() + self.debug_enabled = debug_enabled + + def major_version(self): + """Return the major version number based on the PHP version.""" + return self.phpver[0:3] + + def version_label(self): + """Return the version label based on the PHP version.""" + major_ver = self.major_version() + + if major_ver == '7.0': + version = major_ver[0] + else: + version = major_ver[0] + major_ver[2] + return version + + def driver_name(self, driver, suffix): + """Return the *driver* name with *suffix* after PHP is successfully compiled.""" + return 'php_' + driver + suffix + + def driver_new_name(self, driver, suffix): + """Return the *driver* name with *suffix* based on PHP version and thread.""" + version = self.version_label() + return 'php_' + driver + '_' + version + '_' + self.thread + suffix + + def compiler_version(self): + """Return the appropriate compiler version based on PHP version.""" + VC = 'vc14' + version = self.version_label() + if version >= '72': # Compiler version for PHP 7.2 or above + VC = 'vc15' + return VC + + def phpsrc_root(self, sdk_dir): + """Return the path to the PHP source folder based on *sdk_dir*.""" + vc = self.compiler_version() + return os.path.join(sdk_dir, 'php-sdk', 'phpdev', vc, self.arch, 'php-'+self.phpver+'-src') + + def build_abs_path(self, sdk_dir): + """Return the absolute path to the PHP build folder based on *sdk_dir*.""" + phpsrc = self.phpsrc_root(sdk_dir) + + build_dir = 'Release' + if self.debug_enabled: + build_dir = 'Debug' + + if self.thread == 'ts': + build_dir = build_dir + '_TS' + + if self.arch == 'x64': + build_dir = self.arch + os.sep + build_dir + + return os.path.join(phpsrc, build_dir) + + def remove_old_builds(self, sdk_dir): + """Remove the extensions, e.g. the driver subfolders in php-7.*-src\ext.""" + print('Removing old builds...') + + phpsrc = self.phpsrc_root(sdk_dir) + ext_path = os.path.join(phpsrc, 'ext') + if os.path.exists( ext_path ): + shutil.rmtree(os.path.join(ext_path, 'sqlsrv'), ignore_errors=True) + shutil.rmtree(os.path.join(ext_path, 'pdo_sqlsrv'), ignore_errors=True) + + if self.arch == 'x64': + shutil.rmtree(os.path.join(phpsrc, self.arch), ignore_errors=True) + else: + shutil.rmtree(os.path.join(phpsrc, 'Debug'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Debug_TS'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Release'), ignore_errors=True) + shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) + + def remove_prev_build(self, sdk_dir): + """Remove all binaries and source code in the Release* or Debug* folders""" + print('Removing previous build...') + build_dir = self.build_abs_path(sdk_dir) + os.chdir(build_dir) + os.system('DEL *sqlsrv*') + + # remove the extensions in the phpsrc's release* or debug* folder's ext subfolder + release_ext_path = os.path.join(build_dir, 'ext') + if os.path.exists( release_ext_path ): + shutil.rmtree(os.path.join(release_ext_path, 'sqlsrv'), ignore_errors=True) + shutil.rmtree(os.path.join(release_ext_path, 'pdo_sqlsrv'), ignore_errors=True) + + # next remove the binaries too + os.chdir(release_ext_path) + os.system('DEL *sqlsrv*') + + @staticmethod + def get_logfile_name(): + """Return the filename for the log file based on timestamp.""" + return 'Build_' + datetime.datetime.now().strftime("%Y%m%d_%H%M") + '.log' + + @staticmethod + def update_file_content(file, search_str, new_str): + """Find *search_str* and replace it by *new_str* in a *file*""" + os.chmod(file, stat.S_IWRITE) + f = open(file, 'r') + filedata = f.read() + updatedata = filedata.replace(search_str, new_str) + f = open(file, 'w') + f.write(updatedata) + f.close() + + @staticmethod + def generateMMDD(): + """Return the generated Microsoft PHP Build Version Number""" + d = datetime.date.today() + + startYear = 2009 + startMonth = 4 + passYear = int( '%02d' % d.year ) - startYear + passMonth = int( '%02d' % d.month ) - startMonth + MM = passYear * 12 + passMonth + dd = d.day + + MMDD = "" + str( MM ) + if( dd < 10 ): + return MMDD + "0" + str( dd ) + else: + return MMDD + str( dd ) + + @staticmethod + def get_driver_version(version_file): + """Read the *version_file* and return the driver version.""" + with open(version_file) as f: + for line in f: + if 'SQLVERSION_MAJOR' in line: # major version + major = line.split()[2] + elif 'SQLVERSION_MINOR' in line: # minor version + minor = line.split()[2] + elif 'SQLVERSION_PATCH' in line: # patch + patch = line.split()[2] + break + + return major + '.' + minor + '.' + patch + + @staticmethod + def write_lines_to_copy_source(driver, file): + """Write to file the commands to copy *driver* source.""" + source = '%currDir%' + os.sep + 'Source' + os.sep + driver + dest = '%phpSrc%' + os.sep + 'ext' + os.sep + driver + file.write('@CALL ROBOCOPY ' + source + ' ' + dest + ' /s /xx /xo' + os.linesep) + + source = '%currDir%' + os.sep + 'Source' + os.sep + 'shared' + dest = '%phpSrc%' + os.sep + 'ext' + os.sep + driver + os.sep + 'shared' + file.write('@CALL ROBOCOPY ' + source + ' ' + dest + ' /s /xx /xo' + os.linesep) + + @staticmethod + def download_msphpsql_source(repo, branch, dest_folder = 'Source', clean_up = True): + """Download to *dest_folder* the msphpsql archive of the specified GitHub *repo* and *branch*.""" + try: + work_dir = os.path.dirname(os.path.realpath(__file__)) + + temppath = os.path.join(work_dir, 'temp') + if os.path.exists(temppath): + shutil.rmtree(temppath) + os.makedirs(temppath) + os.chdir(temppath) + + file = branch + '.zip' + url = 'https://github.com/' + repo + '/msphpsql/archive/' + branch + '.zip' + + print('Downloading ' + url + ' ...') + try: + with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file: + shutil.copyfileobj(response, out_file) + except: + print ("Resort to skip ssl verifcation...") + # need to skip ssl verifcation on some agents + # see https://www.python.org/dev/peps/pep-0476/ + with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as response, open(file, 'wb') as out_file: + shutil.copyfileobj(response, out_file) + + print('Extracting ' + file + ' ...') + zip = zipfile.ZipFile(file) + zip.extractall() + zip.close() + + msphpsqlFolder = os.path.join(temppath, 'msphpsql-' + branch) + source = os.path.join(msphpsqlFolder, 'source') + os.chdir(work_dir) + + os.system('ROBOCOPY ' + source + '\shared ' + dest_folder + '\shared /xx /xo') + os.system('ROBOCOPY ' + source + '\pdo_sqlsrv ' + dest_folder + '\pdo_sqlsrv /xx /xo') + os.system('ROBOCOPY ' + source + '\sqlsrv ' + dest_folder + '\sqlsrv /xx /xo') + + if clean_up: + shutil.rmtree(temppath) + + except: + print('Error occurred when downloading source') + raise + + def update_driver_source(self, source_dir, driver): + """Update the *driver* source in *source_path* with the latest version, file descriptions, etc.""" + driver_dir = os.path.join(source_dir, driver) + + # Update Template.rc + template_file = os.path.join(driver_dir, 'template.rc') + if driver == 'sqlsrv': + drivername = self.driver_new_name(driver, '.dll') + self.update_file_content(template_file, 'FILE_NAME \"\\0\"', '"' + drivername + '\\0"') + self.update_file_content(template_file, '\"Microsoft Drivers for PHP for SQL Server\\0\"', '"Microsoft Drivers for PHP for SQL Server (SQLSRV Driver)\\0"') + elif driver == 'pdo_sqlsrv': + drivername = self.driver_new_name(driver, '.dll') + self.update_file_content(template_file, 'FILE_NAME \"\\0\"', '"' + drivername + '\\0"') + self.update_file_content(template_file, '\"Microsoft Drivers for PHP for SQL Server\\0\"', '"Microsoft Drivers for PHP for SQL Server (PDO Driver)\\0"') + + # Update Version.h + version_file = os.path.join(source_dir, 'shared', 'version.h') + build_number = self.generateMMDD() + self.update_file_content(version_file, 'SQLVERSION_BUILD 0', 'SQLVERSION_BUILD ' + build_number) + + # get the latest version + version = self.get_driver_version(version_file) + '.' + build_number + print('Driver version is: ', version) + + # Update CREDIT file + credits_file = os.path.join(driver_dir, 'CREDITS') + if driver == 'sqlsrv': + self.update_file_content(credits_file, 'Microsoft Drivers for PHP for SQL Server', 'Microsoft Drivers ' + version + ' for PHP for SQL Server (' + self.driver.upper() + ' driver)') + elif driver == 'pdo_sqlsrv': + self.update_file_content(credits_file, 'Microsoft Drivers for PHP for SQL Server (PDO driver)', 'Microsoft Drivers ' + version + ' for PHP for SQL Server (' + self.driver.upper() + ' driver)') + + def generate_build_options(self): + """Return the generated build configuration and arguments""" + cmd_line = '' + if self.debug_enabled: + cmd_line = ' --enable-debug ' + + if self.driver == 'all': + cmd_line = ' --enable-sqlsrv=shared --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line + else: + if self.driver == 'sqlsrv': + cmd_line = ' --enable-sqlsrv=shared ' + cmd_line + else: # pdo_sqlsrv + cmd_line = ' --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line + + cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi' + cmd_line + ' --disable-ipv6 --with-odbcver=0x0380 --enable-embed' + if self.thread == 'nts': + cmd_line = cmd_line + ' --disable-zts' + return cmd_line + + def create_local_batch_file(self, make_clean, cmd_line, log_file): + """Generate the batch file to be picked up by the PHP starter script.""" + filename = 'phpsdk-build-task.bat' + print('Generating ', filename) + try: + file = open(filename, 'w') + file.write('@ECHO OFF' + os.linesep) + file.write('SET currDir=%CD%' + os.linesep) + file.write('SET LOG_NAME=%currDir%\\' + log_file + os.linesep) + file.write('@CALL phpsdk_buildtree phpdev > %LOG_NAME% 2>&1' + os.linesep) + + # for PHP version with release tags, such as 'RC', 'beta', etc. + # we need to remove the hyphen '-' between the version number and tag + # because in https://github.com/php/php-src the released tags have no hyphens + + php_tag = 'php-' + self.phpver.replace('-', '') + php_src = 'php-' + self.phpver +'-src' + + # if not exists, check out the specified tag + file.write('IF NOT EXIST ' + php_src + ' @CALL git clone -b ' + php_tag + ' --depth 1 --single-branch https://github.com/php/php-src.git ' + php_src + os.linesep) + file.write('CD ' + php_src + os.linesep) + file.write('SET phpSrc=%CD%' + os.linesep) + file.write('@CALL phpsdk_deps -u >> %LOG_NAME% 2>&1' + os.linesep) + + # copy source files to extension + if self.driver == 'all': + self.write_lines_to_copy_source('sqlsrv', file) + self.write_lines_to_copy_source('pdo_sqlsrv', file) + else: + self.write_lines_to_copy_source(self.driver, file) + + # configure and build + file.write('@CALL buildconf --force >> %LOG_NAME% 2>&1' + os.linesep) + file.write('@CALL ' + cmd_line + ' >> %LOG_NAME% 2>&1' + os.linesep) + if make_clean: + file.write('nmake clean >> %LOG_NAME% 2>&1' + os.linesep) + file.write('nmake >> %LOG_NAME% 2>&1' + os.linesep) + file.write('exit' + os.linesep) + file.close() + return filename + except: + print('Cannot create ', filename) + + def build_drivers(self, make_clean = False, dest = None, log_file = None): + """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder exists in the working directory, and this folder will be removed when the build is complete.""" + work_dir = os.path.dirname(os.path.realpath(__file__)) + + # First, update the driver source file contents + source_dir = os.path.join(work_dir, 'Source') + if self.driver == 'all': + self.update_driver_source(source_dir, 'sqlsrv') + self.update_driver_source(source_dir, 'pdo_sqlsrv') + else: + self.update_driver_source(source_dir, self.driver) + + # Next, generate the build configuration and arguments + cmd_line = self.generate_build_options() + print('cmd_line: ' + cmd_line) + + # Generate a batch file based on the inputs + if log_file is None: + log_file = self.get_logfile_name() + + batch_file = self.create_local_batch_file(make_clean, cmd_line, log_file) + + # Reference: https://github.com/OSTC/php-sdk-binary-tools + # Clone the master branch of PHP sdk if the directory does not exist + print('Downloading the latest php SDK...') + + # if *dest* is None, simply use the current working directory + sdk_dir = dest + copy_to_ext = True # this determines where to copy the binaries to + if dest is None: + sdk_dir = work_dir + copy_to_ext = False + + phpSDK = os.path.join(sdk_dir, 'php-sdk') + if not os.path.exists( phpSDK ): + os.system('git clone https://github.com/OSTC/php-sdk-binary-tools.git --branch master --single-branch --depth 1 ' + phpSDK) + os.chdir(phpSDK) + os.system('git pull ') + + # Copy the generated batch file to phpSDK for the php starter script + shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + shutil.move(source_dir, phpSDK) + + # Invoke phpsdk--.bat + vc = self.compiler_version() + starter_script = 'phpsdk-' + vc + '-' + self.arch + '.bat' + print('Running starter script: ', starter_script) + os.system(starter_script + ' -t ' + batch_file) + + # Now we can safely remove the Source folder, because its contents have + # already been modified when building the extensions + shutil.rmtree(os.path.join(phpSDK, 'Source'), ignore_errors=True) + + # Next, rename the newly compiled PHP extensions + self.rename_binaries(sdk_dir) + + # Final step, copy the binaries to the right place + self.copy_binaries(sdk_dir, copy_to_ext) + + def rename_binary(self, path, driver, suffix): + """Rename sqlsrv or pdo_sqlsrv binary.""" + driver_old_name = self.driver_name(driver, suffix) + driver_new_name = self.driver_new_name(driver, suffix) + + os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) + + def rename_binaries(self, sdk_dir): + """Rename the sqlsrv and/or pdo_sqlsrv binaries based on PHP version and thread, including pdb files.""" + + # Derive the path to where the extensions are located + ext_dir = self.build_abs_path(sdk_dir) + print("Renaming binaries in ", ext_dir) + + if self.driver == 'all': + self.rename_binary(ext_dir, 'sqlsrv', '.dll') + self.rename_binary(ext_dir, 'sqlsrv', '.pdb') + self.rename_binary(ext_dir, 'pdo_sqlsrv', '.dll') + self.rename_binary(ext_dir, 'pdo_sqlsrv', '.pdb') + else: + self.rename_binary(ext_dir, self.driver, '.dll') + self.rename_binary(ext_dir, self.driver, '.pdb') + + def copy_binary(self, from_dir, dest_dir, driver, suffix): + """Copy sqlsrv or pdo_sqlsrv binary to *dest_dir*.""" + binary = self.driver_new_name(driver, suffix) + shutil.copy2(os.path.join(from_dir, binary), dest_dir) + + def copy_binaries(self, sdk_dir, copy_to_ext): + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, to the right place.""" + build_dir = self.build_abs_path(sdk_dir) + print('Copying the binaries from', build_dir) + if copy_to_ext: + dest_dir = os.path.join(build_dir, 'ext') + else: + # Simply make a copy of the binaries in sdk_dir + dest_dir = sdk_dir + + print('Destination:', dest_dir) + + # Now copy the binaries + if self.driver == 'all': + self.copy_binary(build_dir, dest_dir, 'sqlsrv', '.dll') + self.copy_binary(build_dir, dest_dir, 'sqlsrv', '.pdb') + self.copy_binary(build_dir, dest_dir, 'pdo_sqlsrv', '.dll') + self.copy_binary(build_dir, dest_dir, 'pdo_sqlsrv', '.pdb') + else: + self.copy_binary(build_dir, dest_dir, self.driver, '.dll') + self.copy_binary(build_dir, dest_dir, self.driver, '.pdb') + From 82f4d99a84cd43b8b252390e340eee243a33580e Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 08:54:21 -0700 Subject: [PATCH 70/87] modified comments and corrected typo --- buildscripts/builddrivers.py | 20 ++++++++++++-------- buildscripts/buildtools.py | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 03b0c9f6..0bb771b0 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -31,11 +31,7 @@ class BuildDriver(object): """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: Attributes: - phpver # PHP version, e.g. 7.1.*, 7.2.* etc. - driver # all, sqlsrv, or pdo_sqlsrv - arch # x64 or x86 - thread # nts or ts - debug # whether debug is enabled + util # BuildUtil object whose constructor takes phpver, driver, arch, thread, debug repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not @@ -65,10 +61,14 @@ class BuildDriver(object): print('Debug enabled: ', self.util.debug_enabled) def clean_or_remove(self, root_dir, work_dir): - """Check if php source directory already exists. If so, prompt user whether to rebuild, clean, or superclean, meaning to remove the entire php source directory.""" + """Check if php source directory already exists. + If so, prompt user whether to rebuild, clean, or superclean, + meaning to remove the entire php source directory. + """ phpsrc = self.util.phpsrc_root(root_dir) if os.path.exists( phpsrc ): - print(phpsrc + " exists.") + print(phpsrc + " exists.") + print("Choose rebuild(r) if using the same configuration. Choose clean(c) otherwise. If unsure, choose superclean(s).") choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") self.make_clean = False if choice == 'r': @@ -86,7 +86,11 @@ class BuildDriver(object): os.chdir(work_dir) def build_extensions(self, dest, logfile): - """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations.""" + """This takes care of getting the drivers' source files, building the drivers. + If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. + In this case, remote_path must be defined such that the binaries will be copied + to the designated destinations. + """ work_dir = os.path.dirname(os.path.realpath(__file__)) if self.download_source: diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 17f2d4a9..6633371a 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -189,7 +189,9 @@ class BuildUtil(object): @staticmethod def download_msphpsql_source(repo, branch, dest_folder = 'Source', clean_up = True): - """Download to *dest_folder* the msphpsql archive of the specified GitHub *repo* and *branch*.""" + """Download to *dest_folder* the msphpsql archive of the specified + GitHub *repo* and *branch*. The downloaded files will be removed by default. + """ try: work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -207,8 +209,8 @@ class BuildUtil(object): with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file: shutil.copyfileobj(response, out_file) except: - print ("Resort to skip ssl verifcation...") - # need to skip ssl verifcation on some agents + print ("Resort to skip ssl verification...") + # need to skip ssl verification on some agents # see https://www.python.org/dev/peps/pep-0476/ with urllib.request.urlopen(url, context=ssl._create_unverified_context()) as response, open(file, 'wb') as out_file: shutil.copyfileobj(response, out_file) @@ -234,7 +236,9 @@ class BuildUtil(object): raise def update_driver_source(self, source_dir, driver): - """Update the *driver* source in *source_path* with the latest version, file descriptions, etc.""" + """Update the *driver* source in *source_path* with the + latest version, file descriptions, etc. + """ driver_dir = os.path.join(source_dir, driver) # Update Template.rc @@ -327,7 +331,10 @@ class BuildUtil(object): print('Cannot create ', filename) def build_drivers(self, make_clean = False, dest = None, log_file = None): - """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder exists in the working directory, and this folder will be removed when the build is complete.""" + """Build sqlsrv/pdo_sqlsrv extensions for PHP, assuming the Source folder + exists in the working directory, and this folder will be removed when the build + is complete. + """ work_dir = os.path.dirname(os.path.realpath(__file__)) # First, update the driver source file contents @@ -376,7 +383,7 @@ class BuildUtil(object): os.system(starter_script + ' -t ' + batch_file) # Now we can safely remove the Source folder, because its contents have - # already been modified when building the extensions + # already been modified prior to building the extensions shutil.rmtree(os.path.join(phpSDK, 'Source'), ignore_errors=True) # Next, rename the newly compiled PHP extensions @@ -393,7 +400,9 @@ class BuildUtil(object): os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries based on PHP version and thread, including pdb files.""" + """Rename the sqlsrv and/or pdo_sqlsrv binaries based on + PHP version and thread, including pdb files. + """ # Derive the path to where the extensions are located ext_dir = self.build_abs_path(sdk_dir) @@ -414,7 +423,9 @@ class BuildUtil(object): shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, to the right place.""" + """Copy the sqlsrv and/or pdo_sqlsrv binaries, + including pdb files, to the right place. + """ build_dir = self.build_abs_path(sdk_dir) print('Copying the binaries from', build_dir) if copy_to_ext: From 72c9d3a111e0548a35e45c428666fe856d4c9112 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 09:21:36 -0700 Subject: [PATCH 71/87] added more checks for path existence --- buildscripts/builddrivers.py | 13 ++++++++----- buildscripts/buildtools.py | 8 +++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 0bb771b0..b429e14a 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -105,13 +105,16 @@ class BuildDriver(object): source = input("Hit ENTER to reuse '" + self.source_path + "' or provide another path to the Source folder: ") if len(source) == 0: source = self.source_path - - if os.path.exists( source ): + + valid = True + if os.path.exists(source) and os.path.exists(os.path.join(source, 'shared')): + # Checking the existence of 'shared' folder only, assuming + # sqlsrv and/or pdo_sqlsrv are also present if it exists self.source_path = source break - else: - print('The path provided does not exist. Please re-enter.') - + + print("The path provided is invalid. Please re-enter.") + print('Copying source files from', source) os.system('ROBOCOPY ' + source + '\shared ' + work_dir + '\Source\shared /xx /xo ') diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 6633371a..1436f981 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -111,9 +111,15 @@ class BuildUtil(object): shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) def remove_prev_build(self, sdk_dir): - """Remove all binaries and source code in the Release* or Debug* folders""" + """Remove all binaries and source code in the + Release* or Debug* folders according to the current + configuration + """ print('Removing previous build...') build_dir = self.build_abs_path(sdk_dir) + if not os.path.exists(build_dir): + return + os.chdir(build_dir) os.system('DEL *sqlsrv*') From 9142d5a213af06ccef809b9565a031a007cc747d Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 14 Aug 2017 14:58:37 -0700 Subject: [PATCH 72/87] Added code to remove optimization flags for debug build --- buildscripts/builddrivers.py | 38 +++++++++++++++++++++++++----------- buildscripts/buildtools.py | 29 ++++++++++++++++++--------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index b429e14a..a27cf6dc 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -35,7 +35,7 @@ class BuildDriver(object): repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not - package # package name for the binaries + package # package name for the binaries (will be ignored for local builds) remote_path # remote destination to where the drivers will be placed (None for local builds) local # whether the build is local source_path # path to a local source folder @@ -54,42 +54,55 @@ class BuildDriver(object): self.source_path = None # None initially but will be set later if not downloading from GitHub def show_config(self): + print() print('PHP Version: ', self.util.phpver) print('Arch: ', self.util.arch) print('Thread: ', self.util.thread) print('Driver: ', self.util.driver) print('Debug enabled: ', self.util.debug_enabled) + print() def clean_or_remove(self, root_dir, work_dir): - """Check if php source directory already exists. - If so, prompt user whether to rebuild, clean, or superclean, - meaning to remove the entire php source directory. + """Only check this when building locally and not rebuilding. If the php source directory + already exists, this will prompt user whether to rebuild, clean, or superclean, the last option + will remove the entire php source directory. + + :param root_dir: the C:\ drive + :param work_dir: the directory of this script + :outcome: the old binaries, if exist, will be removed """ phpsrc = self.util.phpsrc_root(root_dir) if os.path.exists( phpsrc ): print(phpsrc + " exists.") print("Choose rebuild(r) if using the same configuration. Choose clean(c) otherwise. If unsure, choose superclean(s).") - choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") + build_choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") self.make_clean = False - if choice == 'r': + if build_choice == 'r': print('Will rebuild the binaries') + # only the old binaries based on the current configuration will be removed self.util.remove_prev_build(root_dir) - elif choice == 'c': + elif build_choice == 'c': print('Will make clean') self.make_clean = True - # this step is necessary in case the user has changed the configuration + # all old builds are removed, and this step is necessary because + # the user might have changed the configuration self.util.remove_old_builds(root_dir) else: print('Will remove ' + phpsrc) os.system('RMDIR /s /q ' + phpsrc) - os.chdir(work_dir) + os.chdir(work_dir) # change back to the working directory def build_extensions(self, dest, logfile): """This takes care of getting the drivers' source files, building the drivers. If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. In this case, remote_path must be defined such that the binaries will be copied to the designated destinations. + + :param dest: either None (for remote builds) or the C:\ drive (for local builds) + :param logfile: the name of the logfile + :outcome: the drivers and symbols will renamed and placed in the appropriate location(s) + """ work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -98,6 +111,7 @@ class BuildDriver(object): self.util.download_msphpsql_source(repo, branch) else: # This case only happens when building locally (interactive mode) + # because download_source must be True for remote builds while True: if self.source_path is None: source = input('Enter the full path to the Source folder: ') @@ -153,7 +167,9 @@ class BuildDriver(object): def build(self): - """This is the main entry point of building drivers for PHP.""" + """This is the main entry point of building drivers for PHP. + For local builds, this will loop till the user decides to quit. + """ self.show_config() work_dir = os.path.dirname(os.path.realpath(__file__)) @@ -221,7 +237,7 @@ if __name__ == '__main__': parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") - parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers") + parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers (do not use this when building locally)") args = parser.parse_args() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 1436f981..9b749ac0 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -111,9 +111,8 @@ class BuildUtil(object): shutil.rmtree(os.path.join(phpsrc, 'Release_TS'), ignore_errors=True) def remove_prev_build(self, sdk_dir): - """Remove all binaries and source code in the - Release* or Debug* folders according to the current - configuration + """Remove all binaries and source code in the Release* or Debug* + folders according to the current configuration """ print('Removing previous build...') build_dir = self.build_abs_path(sdk_dir) @@ -244,9 +243,20 @@ class BuildUtil(object): def update_driver_source(self, source_dir, driver): """Update the *driver* source in *source_path* with the latest version, file descriptions, etc. + If debug is enabled, will remove the optimization flag """ driver_dir = os.path.join(source_dir, driver) + if self.debug_enabled: + # Remove the optimization flag in the config file for this driver + # because '/O2' option is incompatible with Debug mode + print('Removing optimization flag for', driver) + config_file = os.path.join(driver_dir, 'config.w32') + if driver == 'sqlsrv': + self.update_file_content(config_file, 'ADD_FLAG( "CFLAGS_SQLSRV", "/O2" );', '') + elif driver == 'pdo_sqlsrv': + self.update_file_content(config_file, 'ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/O2" );', '') + # Update Template.rc template_file = os.path.join(driver_dir, 'template.rc') if driver == 'sqlsrv': @@ -399,15 +409,15 @@ class BuildUtil(object): self.copy_binaries(sdk_dir, copy_to_ext) def rename_binary(self, path, driver, suffix): - """Rename sqlsrv or pdo_sqlsrv binary.""" + """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) based on the *suffix*.""" driver_old_name = self.driver_name(driver, suffix) driver_new_name = self.driver_new_name(driver, suffix) os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries based on - PHP version and thread, including pdb files. + """Rename the sqlsrv and/or pdo_sqlsrv binaries according to the + PHP version and thread, including pdb files (the symbols). """ # Derive the path to where the extensions are located @@ -424,13 +434,14 @@ class BuildUtil(object): self.rename_binary(ext_dir, self.driver, '.pdb') def copy_binary(self, from_dir, dest_dir, driver, suffix): - """Copy sqlsrv or pdo_sqlsrv binary to *dest_dir*.""" + """Copy sqlsrv or pdo_sqlsrv binary (based on *suffix*) to *dest_dir*.""" binary = self.driver_new_name(driver, suffix) shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, - including pdb files, to the right place. + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, + to the right place, depending on *copy_to_ext*. The default is to + copy them to the 'ext' folder. """ build_dir = self.build_abs_path(sdk_dir) print('Copying the binaries from', build_dir) From 5b4d1271a727be4e55e21b801da6f2b645e823de Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 09:50:34 -0700 Subject: [PATCH 73/87] Modified scripts based on review comments --- buildscripts/builddrivers.py | 28 ++++++++++++---------------- buildscripts/buildtools.py | 6 +++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index a27cf6dc..fbd663a3 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -1,10 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/python3 ######################################################################################### # # Description: This script helps to build drivers in a Windows environment for PHP 7+ (32-bit/64-bit) # # Requirement: -# python 3.4 +# python 3.x # PHP SDK and PHP Source # Driver source code folder / GitHub repository # Visual Studio 2015 (PHP 7.0* and 7.1*) and Visual Studio 2017 (PHP 7.2*) @@ -35,18 +35,18 @@ class BuildDriver(object): repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not - package # package name for the binaries (will be ignored for local builds) remote_path # remote destination to where the drivers will be placed (None for local builds) - local # whether the build is local + local # a boolean flag - whether the build is local + rebuild # a boolean flag - whether the user is rebuilding + make_clean # a boolean flag - whether make clean is necessary source_path # path to a local source folder """ - def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, package, path): + def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, path): self.util = BuildUtil(phpver, driver, arch, thread, debug) self.repo = repo self.branch = branch self.download_source = download - self.package = package self.remote_path = path self.local = path is None # the default path is None, which means running locally self.rebuild = False @@ -147,8 +147,7 @@ class BuildDriver(object): if self.remote_path is None: print('Errors: Drivers destination should be defined! Do nothing.') else: - OS_folder = "Windows" # hardcode this since this script is only run in Windows - dest_drivers = os.path.join(self.remote_path, 'PHP', 'Drivers', self.package, OS_folder, self.util.major_version(), self.util.arch) + dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) dest_symbols = os.path.join(dest_drivers, 'Symbols') # All intermediate directories will be created in order to create the leaf directory @@ -236,8 +235,7 @@ if __name__ == '__main__': parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository") parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") - parser.add_argument('-k', '--PACKAGE', default='Latest', help="the package name for the drivers") - parser.add_argument('-p', '--PATH', default=None, help="the remote destination for the drivers (do not use this when building locally)") + parser.add_argument('-p', '--DESTPATH', default=None, help="the remote destination for the drivers (do not use this for local builds)") args = parser.parse_args() @@ -249,19 +247,18 @@ if __name__ == '__main__': repo = args.REPO branch = args.BRANCH download = args.GITHUB.lower() == 'yes' - path = args.PATH - package = args.PACKAGE + path = args.DESTPATH if phpver is None: # assuming it is building drivers locally when required to prompt # thus will not prompt for drivers' destination path, which is None by default phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") - arch_version = input("Want to build 64-bit [y/n]: ") + arch_version = input("64-bit? [y/n]: ") thread = validate_input("Thread safe? ", "nts/ts") driver = validate_input("Driver to build? ", "all/sqlsrv/pdo_sqlsrv") - debug_mode = input("Want to build debug [y/n]? ") + debug_mode = input("Debug enabled? [y/n]: ") - answer = input("Download source from a GitHub repo [y/n]? ") + answer = input("Download source from a GitHub repo? [y/n]: ") download = False if answer == 'yes' or answer == 'y' or answer == '': download = True @@ -286,6 +283,5 @@ if __name__ == '__main__': repo, branch, download, - package, path) builder.build() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 9b749ac0..61c0496a 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -1,11 +1,11 @@ -#!/usr/bin/python +#!/usr/bin/python3 ######################################################################################### # # Description: The class BuildUtil will build Microsoft SQL Server PHP 7+ Drivers # for 32 bit and 64 bit. # # Requirement: -# python 3.4 +# python 3.x # PHP SDK and PHP Source # Driver source code folder # Git for Windows @@ -48,7 +48,7 @@ class BuildUtil(object): """Return the version label based on the PHP version.""" major_ver = self.major_version() - if major_ver == '7.0': + if major_ver[2] == '0': version = major_ver[0] else: version = major_ver[0] + major_ver[2] From f6b848ac356375d9b4a94e723a424034ed861b03 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 11:54:51 -0700 Subject: [PATCH 74/87] added a new README plus modifying the project README --- README.md | 26 ++++++++++++++++---------- buildscripts/builddrivers.py | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6c9c2aeb..b9d9a869 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Thank you for taking time to take our February survey. Let us know how we are do ## Announcements - Please visit the [blog][blog] for more announcements. +Please visit the [blog][blog] for more announcements. ## Build (Windows) @@ -46,23 +46,29 @@ Note: if you prefer, you can use the pre-compiled binary found [HERE](https://gi #### 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. +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. +1. Download the source code directory from this repository -2. Run `buildconf.bat` to rebuild the configure.js script to include the driver. +2. Make a copy of *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder -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` +3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder into the PHP source ext subdirectory. -4. Run `nmake`. It is suggested that you run the entire build. If you wish to do so, run `nmake clean` first. +4. Run `buildconf --force` to rebuild the configure.js script to include the driver. -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. +5. 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 --with-pdo-sqlsrv=shared` -This software has been compiled and tested under PHP 7.0.20 and 7.1.6 using the Visual C++ 2015 compiler. +6. Run `nmake`. Optionally, you can run `nmake clean` first. + +7. 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. + +The extensions have been compiled and tested with the PHP 7.0.* and 7.1.* using the Visual C++ 2015 compiler as well as PHP 7.2.0 beta using the Visual C++ 2017 V15.0. + +For an example of how to automate building the Microsoft Drivers for PHP for SQL Server, please browse the *buildscripts* directory. ## Install (Windows) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index fbd663a3..a67af601 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -145,7 +145,7 @@ class BuildDriver(object): # Make sure drivers path is defined if self.remote_path is None: - print('Errors: Drivers destination should be defined! Do nothing.') + print('Errors: Drivers destination should be defined! Doing nothing.') else: dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) dest_symbols = os.path.join(dest_drivers, 'Symbols') From aeaa61cc934523916abf7e3fde7d95e13a48ded1 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 13:20:20 -0700 Subject: [PATCH 75/87] README for build scripts --- buildscripts/README.md | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 buildscripts/README.md diff --git a/buildscripts/README.md b/buildscripts/README.md new file mode 100644 index 00000000..ffe79f26 --- /dev/null +++ b/buildscripts/README.md @@ -0,0 +1,56 @@ +## Windows + +### Prerequisites +To use the Python build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x. + +To build extensions for PHP 7.0* or 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. + +For PHP 7.2*, install Visual Studio 2017, and make sure Visual C++ toolset, the Windows SDK components, and Git for Windows are installed. + +See [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for more details. + +### Build PHP extensions + +Launch a regular `cmd` prompt and change to the directory where these Python scripts are. + +You'll be asked to input the PHP version. Simply type the version number like `7.1.7`. + +If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit https://github.com/php/php-src to find the appropriate tag names. + +**Use Interactive mode** + +Run `py builddrivers.py` + +Most questions are self-explanatory. Use lower cases for your inputs, and you can simply hit `ENTER` key for `yes/no` questions. + +When given a choice whether to download from a GitHub repository, you can choose to provide the full path to your local Source folder instead. + +**Use Command-line arguments** + +Run `py builddrivers.py` with command line arguments. For example: + +`py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` + +or + +`py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` + +**Notes** + +It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. + +If this is not the first time you build the drivers for a PHP version with certain configuration options (such as arch, thread safe, etc.), you will be prompted whether to rebuild, clean or superclean. Choose `rebuild` if you have always used the same configuration. Otherwise, choose `clean` to remove previous builds (binaries). The last option will remove the entire `php--src` directory, which is often unnecessary. + +When something goes wrong during the build, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. + +After the compilation is complete, you will be given the option to rebuild or quit. If you choose rebuild, the extensions will be re-compiled (say after you have changed any source or header file). This script will keep running until you choose to quit. + +In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. + +When running build unattended, you should specify the destination path `--DESTPATH=`. In such case, the `php-sdk` folder will be created in the same working directory of these build scripts, and the drivers will be copied to your designated path. The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. + + + + + + From 26bb1d62af31f0ac3ac114ddc8e6066e5167a839 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 15 Aug 2017 16:15:59 -0700 Subject: [PATCH 76/87] updated update_file_content as per review comment --- buildscripts/buildtools.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 61c0496a..32423d37 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -21,6 +21,7 @@ import stat import datetime import urllib.request import zipfile +import fileinput class BuildUtil(object): """Build sqlsrv and/or pdo_sqlsrv drivers with PHP source with the following properties: @@ -141,12 +142,9 @@ class BuildUtil(object): def update_file_content(file, search_str, new_str): """Find *search_str* and replace it by *new_str* in a *file*""" os.chmod(file, stat.S_IWRITE) - f = open(file, 'r') - filedata = f.read() - updatedata = filedata.replace(search_str, new_str) - f = open(file, 'w') - f.write(updatedata) - f.close() + with fileinput.FileInput(file, inplace=True) as f: + for line in f: + print(line.replace(search_str, new_str), end='') @staticmethod def generateMMDD(): @@ -390,6 +388,12 @@ class BuildUtil(object): # Copy the generated batch file to phpSDK for the php starter script shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + sdk_source = os.path.join(phpSDK, 'Source') + # Sometimes, for various reasons, the Source folder from previous build + # might exist in phpSDK. If so, remove it first + if os.path.exists(sdk_source): + os.chmod(sdk_source, stat.S_IWRITE) + shutil.rmtree(sdk_source, ignore_errors=True) shutil.move(source_dir, phpSDK) # Invoke phpsdk--.bat From 2ae378227eb6567a00db80e88ee2f38646b1d98e Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 09:19:27 -0700 Subject: [PATCH 77/87] No longer renamed the pdb files --- buildscripts/builddrivers.py | 2 +- buildscripts/buildtools.py | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index a67af601..4005cbbf 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -148,7 +148,7 @@ class BuildDriver(object): print('Errors: Drivers destination should be defined! Doing nothing.') else: dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) - dest_symbols = os.path.join(dest_drivers, 'Symbols') + dest_symbols = os.path.join(dest_drivers, 'Symbols', self.util.thread) # All intermediate directories will be created in order to create the leaf directory if os.path.exists(dest_symbols) == False: diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 32423d37..0875398f 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -386,8 +386,12 @@ class BuildUtil(object): os.chdir(phpSDK) os.system('git pull ') - # Copy the generated batch file to phpSDK for the php starter script - shutil.copy(os.path.join(work_dir, batch_file), phpSDK) + # Move the generated batch file to phpSDK for the php starter script + sdk_batch_file = os.path.join(phpSDK, batch_file) + if os.path.exists(sdk_batch_file): + os.remove(sdk_batch_file) + shutil.move(os.path.join(work_dir, batch_file), phpSDK) + sdk_source = os.path.join(phpSDK, 'Source') # Sometimes, for various reasons, the Source folder from previous build # might exist in phpSDK. If so, remove it first @@ -412,16 +416,16 @@ class BuildUtil(object): # Final step, copy the binaries to the right place self.copy_binaries(sdk_dir, copy_to_ext) - def rename_binary(self, path, driver, suffix): - """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) based on the *suffix*.""" - driver_old_name = self.driver_name(driver, suffix) - driver_new_name = self.driver_new_name(driver, suffix) + def rename_binary(self, path, driver): + """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) (only the dlls).""" + driver_old_name = self.driver_name(driver, '.dll') + driver_new_name = self.driver_new_name(driver, '.dll') os.rename(os.path.join(path, driver_old_name), os.path.join(path, driver_new_name)) def rename_binaries(self, sdk_dir): - """Rename the sqlsrv and/or pdo_sqlsrv binaries according to the - PHP version and thread, including pdb files (the symbols). + """Rename the sqlsrv and/or pdo_sqlsrv dlls according to the PHP + version and thread. """ # Derive the path to where the extensions are located @@ -429,21 +433,21 @@ class BuildUtil(object): print("Renaming binaries in ", ext_dir) if self.driver == 'all': - self.rename_binary(ext_dir, 'sqlsrv', '.dll') - self.rename_binary(ext_dir, 'sqlsrv', '.pdb') - self.rename_binary(ext_dir, 'pdo_sqlsrv', '.dll') - self.rename_binary(ext_dir, 'pdo_sqlsrv', '.pdb') + self.rename_binary(ext_dir, 'sqlsrv') + self.rename_binary(ext_dir, 'pdo_sqlsrv') else: - self.rename_binary(ext_dir, self.driver, '.dll') - self.rename_binary(ext_dir, self.driver, '.pdb') + self.rename_binary(ext_dir, self.driver) def copy_binary(self, from_dir, dest_dir, driver, suffix): """Copy sqlsrv or pdo_sqlsrv binary (based on *suffix*) to *dest_dir*.""" - binary = self.driver_new_name(driver, suffix) + if suffix == '.dll': + binary = self.driver_new_name(driver, suffix) + else: + binary = self.driver_name(driver, suffix) shutil.copy2(os.path.join(from_dir, binary), dest_dir) def copy_binaries(self, sdk_dir, copy_to_ext): - """Copy the sqlsrv and/or pdo_sqlsrv binaries, including pdb files, + """Copy the sqlsrv and/or pdo_sqlsrv binaries, including the pdb files, to the right place, depending on *copy_to_ext*. The default is to copy them to the 'ext' folder. """ From be74169501b722c0cc06fc48ac0df878da7b6a66 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 13:04:26 -0700 Subject: [PATCH 78/87] Modified README files and removed odbc requirement to build --- buildscripts/README.md | 93 ++++++++++++++++++++++++++++---------- buildscripts/buildtools.py | 2 +- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/buildscripts/README.md b/buildscripts/README.md index ffe79f26..da71851d 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -1,53 +1,96 @@ -## Windows +# Windows -### Prerequisites -To use the Python build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x. +## Prerequisites -To build extensions for PHP 7.0* or 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. +To build extensions for + * PHP 7.0* or PHP 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. + * PHP 7.2*, install Visual Studio 2017, including Visual C++ toolset, the Windows SDK components, and Git for Windows. -For PHP 7.2*, install Visual Studio 2017, and make sure Visual C++ toolset, the Windows SDK components, and Git for Windows are installed. +To use the sample build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x in Windows. -See [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for more details. +## Compile the drivers -### Build PHP extensions +You must first be able to build PHP 7.* without including these extensions. For help with doing this, see the [official PHP website](https://wiki.php.net/internals/windows/stepbystepbuild) for building PHP 7.0* or PHP 7.1* on Windows or [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for the new instructions for building PHP 7.2 and/or above. -Launch a regular `cmd` prompt and change to the directory where these Python scripts are. +The Microsoft Drivers for PHP for SQL Server have been compiled and tested with PHP 7.0.* and 7.1.* using the Visual C++ 2015 as well as PHP 7.2.0 beta using the Visual C++ 2017 v15.0. -You'll be asked to input the PHP version. Simply type the version number like `7.1.7`. +### Manually building from source -If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit https://github.com/php/php-src to find the appropriate tag names. +1. Download the *source* directory from this repository -**Use Interactive mode** +2. Make a copy of the *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder -Run `py builddrivers.py` +3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder(s) into the PHP source ext subdirectory -Most questions are self-explanatory. Use lower cases for your inputs, and you can simply hit `ENTER` key for `yes/no` questions. +4. Run `buildconf --force` to rebuild the configure.js script to include the *sqlsrv* and/or *pdo_sqlsrv* driver(s). -When given a choice whether to download from a GitHub repository, you can choose to provide the full path to your local Source folder instead. +5. Run `configure.bat` with the desired driver options (as shown below) to generate the makefile. You can run `configure.bat --help` to see what other options are available. For example, for non-thread safe build, add this option `--disable-zts`. + * For SQLSRV add: `--enable-sqlsrv=shared` + * For PDO_SQLSRV add: `--enable-pdo --with-pdo-sqlsrv=shared` -**Use Command-line arguments** +6. Run `nmake`. Optionally, you can run `nmake clean` first. -Run `py builddrivers.py` with command line arguments. For example: +7. To install the drivers, there are two ways: + * Run `nmake install`, or + * Copy the drivers: + * Find the directory where the newly compiled `php.exe` is + * Locate the compiled php_sqlsrv.dll and/or php_pdo_sqlsrv.dll + * Copy the dll(s) to the `ext` subfolder -`py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` +### Using the sample build scripts -or +The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to build our extensions for PHP in Windows. -`py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` +#### Overview -**Notes** +When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. +It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. -If this is not the first time you build the drivers for a PHP version with certain configuration options (such as arch, thread safe, etc.), you will be prompted whether to rebuild, clean or superclean. Choose `rebuild` if you have always used the same configuration. Otherwise, choose `clean` to remove previous builds (binaries). The last option will remove the entire `php--src` directory, which is often unnecessary. +#### Steps + +1. Launch a regular `cmd` prompt + +2. Change to the directory where the Python scripts `builddrivers.py` and `buildtools.py` are + +3. Interactive mode: + * Run `py builddrivers.py` to use the interactive mode. Use lower cases to answer the following questions: + * PHP Version (i.e. the version number like `7.1.7` or `7.2.0beta2`) + * 64-bit? + * Thread safe? + * Driver? + * Debug enabled? + * Download source from GitHub? + * For `yes/no` questions, you can simply hit `ENTER` key for `yes`. Other questions are self-explanatory. + +4. Use Command-line arguments + * Run `py builddrivers.py -h` to get a list of options and their descriptions + * For example, + * `py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` + * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` + +5. If the script detects the presence of a PHP source directory, you will be prompted whether to rebuild, clean or superclean. Choose + * `rebuild` if you have always used the same configuration (32 bit, thread safe, etc.) + * `clean` to remove previous builds (binaries) + * `superclean` to remove the entire `php--src` directory, which is often unnecessary + +6. If you choose not to download from a GitHub repository, you will be asked to provide the full path to your local Source folder. + +7. If the compilation is successful, you will be given the option to rebuild or quit. + +#### Troubleshooting When something goes wrong during the build, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. -After the compilation is complete, you will be given the option to rebuild or quit. If you choose rebuild, the extensions will be re-compiled (say after you have changed any source or header file). This script will keep running until you choose to quit. - In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. -When running build unattended, you should specify the destination path `--DESTPATH=`. In such case, the `php-sdk` folder will be created in the same working directory of these build scripts, and the drivers will be copied to your designated path. The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. +#### Building the extensions unattended + +You can invoke `py builddrivers.py` with the desired options plus the destination path `--DESTPATH=`. + +In such case, the `php-sdk` folder will be created in the same directory of these build scripts. Note that the PHP drivers will also be copied to the designated path. + +The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 0875398f..d527febb 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -296,7 +296,7 @@ class BuildUtil(object): else: # pdo_sqlsrv cmd_line = ' --enable-pdo --with-pdo-sqlsrv=shared ' + cmd_line - cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi' + cmd_line + ' --disable-ipv6 --with-odbcver=0x0380 --enable-embed' + cmd_line = 'cscript configure.js --disable-all --enable-cli --enable-cgi --enable-embed' + cmd_line if self.thread == 'nts': cmd_line = cmd_line + ' --disable-zts' return cmd_line From 621f13327675b469a37e39ba6798d889dc64b3d1 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 14:12:26 -0700 Subject: [PATCH 79/87] Reverted some changes in README --- README.md | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b9d9a869..de5a6566 100644 --- a/README.md +++ b/README.md @@ -42,33 +42,9 @@ 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) +If you prefer, you can use the pre-compiled binaries 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. Download the source code directory from this repository - -2. Make a copy of *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder - -3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder into the PHP source ext subdirectory. - -4. Run `buildconf --force` to rebuild the configure.js script to include the driver. - -5. 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 --with-pdo-sqlsrv=shared` - -6. Run `nmake`. Optionally, you can run `nmake clean` first. - -7. 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. - -The extensions have been compiled and tested with the PHP 7.0.* and 7.1.* using the Visual C++ 2015 compiler as well as PHP 7.2.0 beta using the Visual C++ 2017 V15.0. - -For an example of how to automate building the Microsoft Drivers for PHP for SQL Server, please browse the *buildscripts* directory. +The *buildscripts* directory contains step by step instructions on how to build the Microsoft Drivers for PHP for SQL Server. You can either build the extensions manually or use the sample scripts provided, which help automate the process. ## Install (Windows) From 791f95c6c01defb2d9408f4ca174dd1b96a9df09 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 16 Aug 2017 14:41:30 -0700 Subject: [PATCH 80/87] reverted README --- README.md | 87 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 99ecc660..f877f5b3 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,39 @@ Thank you for taking time to take our February survey. Let us know how we are do * [**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) +* [**SUSE + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/sles) * [**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. + Please visit the [blog][blog] for more announcements. ## Build (Windows) -If you prefer, you can use the pre-compiled binaries found [HERE](https://github.com/Microsoft/msphpsql/releases) +Note: if you prefer, you can use the pre-compiled binary found [HERE](https://github.com/Microsoft/msphpsql/releases) -The *buildscripts* directory contains step by step instructions on how to build the Microsoft Drivers for PHP for SQL Server. You can either build the extensions manually or use the sample scripts provided, which help automate the process. +#### 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) @@ -62,7 +81,7 @@ The *buildscripts* directory contains step by step instructions on how to build 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. +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, SUSE 12, and macOS. ### Step 1: Install PHP7+ @@ -102,7 +121,13 @@ The following instructions assume a clean environment and show how to install PH apt-get update apt-get install -y php7.0 php-pear php7.0-dev php7.0-xml -**Mac OS** +**SUSE 12** + + sudo su + zypper refresh + zypper install -y php7 php7-pear php7-devel + +**macOS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -145,7 +170,14 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. apt-get update apt-get install -y php7.1 php-pear php7.1-dev php7.1-xml -**Mac OS** +**SUSE 12** + + sudo su + zypper -n ar -f http://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_42.3/ devel:languages:php + zypper --gpg-auto-import-keys refresh + zypper -n install php7 php7-pear php7-devel + +**macOS** /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap @@ -212,7 +244,20 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. sudo ACCEPT_EULA=Y apt-get install msodbcsql sudo apt-get install unixodbc-dev -**Mac OS** +**SUSE 12** + + sudo su + zypper ar https://packages.microsoft.com/config/sles/12/prod.repo + sudo zypper --gpg-auto-import-keys refresh + exit + sudo ACCEPT_EULA=Y zypper install msodbcsql + sudo ACCEPT_EULA=Y zypper install mssql-tools + sudo zypper install unixODBC-devel + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile + echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc + source ~/.bashrc + +**macOS** brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release brew update @@ -226,7 +271,7 @@ Note that there are no PHP 7.1 packages available for Ubuntu 15.10. *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: +On Ubuntu, Debian, and SUSE systems only, run: sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system @@ -256,7 +301,15 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini -**Mac OS** +**SUSE** + + sudo su + zypper install apache2 apache2-mod_php7 + a2enmod php7 + echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini + +**macOS** (echo ""; echo "SetHandler application/x-httpd-php"; echo "";) >> /usr/local/etc/apache2/2.4/httpd.conf @@ -279,14 +332,22 @@ On all systems, run: echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini -**Mac OS** +**SUSE** + + sudo su + zypper install apache2 apache2-mod_php7 + a2enmod php7 + echo "extension=sqlsrv.so" >> /etc/php7/apache2/php.ini + echo "extension=pdo_sqlsrv.so" >> /etc/php7/apache2/php.ini + +**macOS** (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** +**Ubuntu, Debian, and SUSE** sudo systemctl restart apache2 @@ -298,13 +359,13 @@ Note: On RedHat, SELinux is installed by default and runs in Enforcing mode. To sudo setsebool -P httpd_can_network_connect_db 1 -**Mac OS** +**macOS** sudo apachectl restart ### 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. +Navigate to your system's document root -- `/var/www/html` on Ubuntu, Debian, and Redhat, `/srv/www/htdocs` on SUSE, or `/usr/local/var/www/htdocs` on Mac. 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, 16 Aug 2017 16:09:11 -0700 Subject: [PATCH 81/87] modified README for build scripts --- buildscripts/README.md | 10 ++++------ buildscripts/builddrivers.py | 14 +++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/buildscripts/README.md b/buildscripts/README.md index da71851d..584c3c3c 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -69,7 +69,7 @@ It's recommended that the PHP SDK is unzipped into the shortest possible path, p * `py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` -5. If the script detects the presence of a PHP source directory, you will be prompted whether to rebuild, clean or superclean. Choose +5. Based on the given configuration, if the script detects the presence of the PHP source directory, you can choose whether to rebuild, clean or superclean: * `rebuild` if you have always used the same configuration (32 bit, thread safe, etc.) * `clean` to remove previous builds (binaries) * `superclean` to remove the entire `php--src` directory, which is often unnecessary @@ -84,13 +84,11 @@ When something goes wrong during the build, the log file will be launched (you c In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. -#### Building the extensions unattended +#### Variation -You can invoke `py builddrivers.py` with the desired options plus the destination path `--DESTPATH=`. +If you want the PHP drivers to be copied to somewhere else, you can invoke `py builddrivers.py` by providing the option `--DESTPATH=`. -In such case, the `php-sdk` folder will be created in the same directory of these build scripts. Note that the PHP drivers will also be copied to the designated path. - -The script `builddrivers.py` provides an example for this case. Again, it's your choice whether to remove the `php-sdk` folder afterwards. +In this case, you will find a copy of the drivers (unless the build fails) and the `php-sdk` folder created in the same directory of these Python scripts. It's your choice whether to remove the `php-sdk` folder and/or the drivers' binaries afterwards. diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 4005cbbf..d02c478b 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -197,7 +197,7 @@ class BuildDriver(object): # Only ask when building locally if self.local: - choice = input("Rebuild the same configuration(yes) or quit (no) [yes/no]: ") + choice = input("Rebuild using the same configuration(yes) or quit (no) [yes/no]: ") if choice.lower() == 'yes' or choice.lower() == 'y' or choice.lower() == '': print('Rebuilding drivers...') @@ -230,12 +230,12 @@ if __name__ == '__main__': parser.add_argument('-v', '--PHPVER', help="PHP version, e.g. 7.1.*, 7.2.* etc.") parser.add_argument('-a', '--ARCH', choices=['x64', 'x86']) parser.add_argument('-t', '--THREAD', choices=['nts', 'ts']) - parser.add_argument('-d', '--DRIVER', choices=['all', 'sqlsrv', 'pdo_sqlsrv']) - parser.add_argument('-m', '--DEBUG', default='no', choices=['yes', 'no'], help="enable debug mode") - parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository") - parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch") - parser.add_argument('-g', '--GITHUB', default='yes', help="get source from GitHub or not") - parser.add_argument('-p', '--DESTPATH', default=None, help="the remote destination for the drivers (do not use this for local builds)") + parser.add_argument('-d', '--DRIVER', default='all', choices=['all', 'sqlsrv', 'pdo_sqlsrv'], help="driver to build (default: all)") + parser.add_argument('-m', '--DEBUG', default='no', choices=['yes', 'no'], help="enable debug mode (default: no)") + parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)") + parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch (default: dev)") + parser.add_argument('-g', '--GITHUB', default='yes', choices=['yes', 'no'], help="get source from GitHub (default: yes)") + parser.add_argument('-p', '--DESTPATH', default=None, help="the remote destination for the drivers (default: None)") args = parser.parse_args() From 1a7c1d89ce6eaab13b49982afef656b319047480 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Thu, 17 Aug 2017 09:16:57 -0700 Subject: [PATCH 82/87] modified some wordings in the scripts and README --- buildscripts/README.md | 17 +++++++++-------- buildscripts/builddrivers.py | 11 +++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/buildscripts/README.md b/buildscripts/README.md index 584c3c3c..aa407ec0 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -43,9 +43,9 @@ The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to #### Overview -When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. +When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC version, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -It's recommended that the PHP SDK is unzipped into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` folder will remain unless you remove it yourself. For ongoing development, it's suggested you keep it around. The build scripts will handle updating the PHP SDK if new version is available. +PHP recommendeds to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. #### Steps @@ -55,7 +55,7 @@ It's recommended that the PHP SDK is unzipped into the shortest possible path, p 3. Interactive mode: * Run `py builddrivers.py` to use the interactive mode. Use lower cases to answer the following questions: - * PHP Version (i.e. the version number like `7.1.7` or `7.2.0beta2`) + * PHP Version (e.g. `7.1.7` or `7.2.0beta2`) * 64-bit? * Thread safe? * Driver? @@ -70,7 +70,7 @@ It's recommended that the PHP SDK is unzipped into the shortest possible path, p * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` 5. Based on the given configuration, if the script detects the presence of the PHP source directory, you can choose whether to rebuild, clean or superclean: - * `rebuild` if you have always used the same configuration (32 bit, thread safe, etc.) + * `rebuild` to build again using the same configuration (32 bit, thread safe, etc.) * `clean` to remove previous builds (binaries) * `superclean` to remove the entire `php--src` directory, which is often unnecessary @@ -80,15 +80,16 @@ It's recommended that the PHP SDK is unzipped into the shortest possible path, p #### Troubleshooting -When something goes wrong during the build, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. +If something went wrong or the build failed, the log file will be launched (you can find the log files in `C:\php-sdk`). Otherwise, the log file will not be shown, and they remain in `C:\php-sdk` until you remove them manually. In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. -#### Variation +#### Setting alternative destination for drivers -If you want the PHP drivers to be copied to somewhere else, you can invoke `py builddrivers.py` by providing the option `--DESTPATH=`. +If your main goal is to build the drivers, and/or there is no need to keep the `php-sdk` directory around, you can invoke `py builddrivers.py` with the necessary command-line arguments plus `--DESTPATH=`, which is **None** by default. Note that this option is not available in the interactive mode. + +By setting an alternative destination automatically turns off the looping mechanism. When the build is finished, you will find a copy of the drivers (unless the build failed) and the `php-sdk` folder in the same directory of these Python scripts. This option is particularly useful in a test environment (or a virtual machine) in which these build scripts are copied to a temporary folder. After the drivers have been successfully compiled and copied to the designated location, the temporary folder can be safely removed afterwards. -In this case, you will find a copy of the drivers (unless the build fails) and the `php-sdk` folder created in the same directory of these Python scripts. It's your choice whether to remove the `php-sdk` folder and/or the drivers' binaries afterwards. diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index d02c478b..2cecc055 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -74,8 +74,7 @@ class BuildDriver(object): phpsrc = self.util.phpsrc_root(root_dir) if os.path.exists( phpsrc ): print(phpsrc + " exists.") - print("Choose rebuild(r) if using the same configuration. Choose clean(c) otherwise. If unsure, choose superclean(s).") - build_choice = validate_input("Want to rebuild (r), clean (c) or superclean (s)? ", "r/c/s") + build_choice = validate_input("(r)ebuild for the same configuration, (c)lean otherwise, (s)uperclean if unsure ", "r/c/s") self.make_clean = False if build_choice == 'r': print('Will rebuild the binaries') @@ -189,7 +188,7 @@ class BuildDriver(object): self.build_extensions(dest, logfile) print('Build Completed') except: - print('Something went wrong. Build incomplete.') + print('Something went wrong, launching log file', logfile) if self.local: # display log file only when building locally os.startfile(os.path.join(root_dir, 'php-sdk', logfile)) os.chdir(work_dir) @@ -198,8 +197,8 @@ class BuildDriver(object): # Only ask when building locally if self.local: choice = input("Rebuild using the same configuration(yes) or quit (no) [yes/no]: ") - - if choice.lower() == 'yes' or choice.lower() == 'y' or choice.lower() == '': + choice = choice.lower() + if choice == 'yes' or choice == 'y' or choice == '': print('Rebuilding drivers...') self.make_clean = False self.rebuild = True @@ -235,7 +234,7 @@ if __name__ == '__main__': parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)") parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch (default: dev)") parser.add_argument('-g', '--GITHUB', default='yes', choices=['yes', 'no'], help="get source from GitHub (default: yes)") - parser.add_argument('-p', '--DESTPATH', default=None, help="the remote destination for the drivers (default: None)") + parser.add_argument('-p', '--DESTPATH', default=None, help="an alternative destination for the drivers (default: None)") args = parser.parse_args() From 0439df396ca005b114095e3529d61fdb9e380cfa Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Thu, 17 Aug 2017 13:24:12 -0700 Subject: [PATCH 83/87] corrected typo and modified the wordings --- buildscripts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscripts/README.md b/buildscripts/README.md index aa407ec0..3ade48c7 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -45,7 +45,7 @@ The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC version, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -PHP recommendeds to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. +PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. #### Steps @@ -88,7 +88,7 @@ In addition to the log files in `C:\php-sdk`, you can examine the contents of `C If your main goal is to build the drivers, and/or there is no need to keep the `php-sdk` directory around, you can invoke `py builddrivers.py` with the necessary command-line arguments plus `--DESTPATH=`, which is **None** by default. Note that this option is not available in the interactive mode. -By setting an alternative destination automatically turns off the looping mechanism. When the build is finished, you will find a copy of the drivers (unless the build failed) and the `php-sdk` folder in the same directory of these Python scripts. This option is particularly useful in a test environment (or a virtual machine) in which these build scripts are copied to a temporary folder. After the drivers have been successfully compiled and copied to the designated location, the temporary folder can be safely removed afterwards. +Setting an alternative destination automatically turns off the looping mechanism. When the build is finished, you will find a copy of the drivers (unless the build failed) and the `php-sdk` folder in the same directory of these Python scripts. This option is particularly useful in a test environment (or a virtual machine) in which these build scripts are copied to a temporary folder. After the drivers have been successfully compiled and copied to the designated location, the temporary folder can be safely removed. From 9667e2a303d84625984390ff1cbff48a23e840e1 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 18 Aug 2017 10:25:19 -0700 Subject: [PATCH 84/87] modified some input arguments to allow the user to set TESTING mode --- buildscripts/README.md | 16 ++-- buildscripts/builddrivers.py | 140 ++++++++++++++++++----------------- buildscripts/buildtools.py | 5 +- 3 files changed, 83 insertions(+), 78 deletions(-) diff --git a/buildscripts/README.md b/buildscripts/README.md index 3ade48c7..3a533c27 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -45,7 +45,7 @@ The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC version, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will create a `php-sdk` folder in the C:\ drive. This `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. +PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will by default create a `php-sdk` folder in the C:\ drive, and this `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. #### Steps @@ -66,8 +66,8 @@ PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably 4. Use Command-line arguments * Run `py builddrivers.py -h` to get a list of options and their descriptions * For example, - * `py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no` - * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --GITHUB=yes` + * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --SOURCE` + * `py builddrivers.py --PHPVER=7.1.8 --ARCH=x86 --THREAD=ts --DEBUG` 5. Based on the given configuration, if the script detects the presence of the PHP source directory, you can choose whether to rebuild, clean or superclean: * `rebuild` to build again using the same configuration (32 bit, thread safe, etc.) @@ -84,13 +84,13 @@ If something went wrong or the build failed, the log file will be launched (you In addition to the log files in `C:\php-sdk`, you can examine the contents of `C:\php-sdk\phpsdk-build-task.bat`, which is overwritten every time you run the build scripts. -#### Setting alternative destination for drivers - -If your main goal is to build the drivers, and/or there is no need to keep the `php-sdk` directory around, you can invoke `py builddrivers.py` with the necessary command-line arguments plus `--DESTPATH=`, which is **None** by default. Note that this option is not available in the interactive mode. - -Setting an alternative destination automatically turns off the looping mechanism. When the build is finished, you will find a copy of the drivers (unless the build failed) and the `php-sdk` folder in the same directory of these Python scripts. This option is particularly useful in a test environment (or a virtual machine) in which these build scripts are copied to a temporary folder. After the drivers have been successfully compiled and copied to the designated location, the temporary folder can be safely removed. +#### Testing mode and/or setting alternative destination +If your main goal is to build the drivers for testing, and/or there is no need to keep the `php-sdk` directory around, you can invoke `py builddrivers.py` with the necessary command-line arguments plus `--TESTING`, which turns on the *testing* mode (it is False by default). +Setting the testing mode automatically turns off the looping mechanism. When the build is finished, you will find a copy of the drivers (unless the build failed) and the `php-sdk` folder in the same directory of these Python scripts. + +In addition, you can set an alternative destination using `--DESTPATH=`, which is **None** by default. Note that these two options are *not* available in the interactive mode. However, they are particularly useful for testing purposes (such as testing in a virtual machine) in which these build scripts are copied to a temporary folder. After the drivers have been successfully compiled and copied to the designated location, the temporary folder can be safely removed. diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 2cecc055..f4e14e34 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -12,12 +12,11 @@ # Execution: Run with command line with required options. # Examples: # py builddrivers.py (for interactive mode) -# py builddrivers.py -v=7.1.7 -a=x86 -t=ts -d=all -g=no -# py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=all --GITHUB=yes +# py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=all --DEBUG # -# Output: Build the drivers using PHP SDK. When running locally, if build is unsuccessful, +# Output: Build the drivers using PHP SDK. When running for local development, if build is unsuccessful, # the log file will be launched for examination. Otherwise, the drivers will be renamed -# and copied to the designated location(s). +# and copied to the designated location (if defined). # ############################################################################################# @@ -35,20 +34,20 @@ class BuildDriver(object): repo # GitHub repository branch # GitHub repository branch download_source # download source from GitHub or not - remote_path # remote destination to where the drivers will be placed (None for local builds) - local # a boolean flag - whether the build is local + dest_path # alternative destination for the drivers (None for development builds) rebuild # a boolean flag - whether the user is rebuilding make_clean # a boolean flag - whether make clean is necessary source_path # path to a local source folder + testing # whether the user has turned on testing mode """ - def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, path): + def __init__(self, phpver, driver, arch, thread, debug, repo, branch, download, path, testing): self.util = BuildUtil(phpver, driver, arch, thread, debug) self.repo = repo self.branch = branch self.download_source = download - self.remote_path = path - self.local = path is None # the default path is None, which means running locally + self.dest_path = path + self.testing = testing self.rebuild = False self.make_clean = False self.source_path = None # None initially but will be set later if not downloading from GitHub @@ -63,7 +62,7 @@ class BuildDriver(object): print() def clean_or_remove(self, root_dir, work_dir): - """Only check this when building locally and not rebuilding. If the php source directory + """Only check this for local development and not rebuilding. If the php source directory already exists, this will prompt user whether to rebuild, clean, or superclean, the last option will remove the entire php source directory. @@ -92,25 +91,22 @@ class BuildDriver(object): os.chdir(work_dir) # change back to the working directory - def build_extensions(self, dest, logfile): + def build_extensions(self, root_dir, logfile): """This takes care of getting the drivers' source files, building the drivers. - If running locally, *dest* should be the root drive. Otherwise, *dest* should be None. - In this case, remote_path must be defined such that the binaries will be copied - to the designated destinations. + If dest_path is defined, the binaries will be copied to the designated destinations. - :param dest: either None (for remote builds) or the C:\ drive (for local builds) + :param root_dir: the root directory :param logfile: the name of the logfile :outcome: the drivers and symbols will renamed and placed in the appropriate location(s) """ work_dir = os.path.dirname(os.path.realpath(__file__)) - + if self.download_source: - # This will download from the specified branch on GitHub repo and copy the source to the working directory + # This will download from the specified branch on GitHub repo and copy the source self.util.download_msphpsql_source(repo, branch) else: - # This case only happens when building locally (interactive mode) - # because download_source must be True for remote builds + # This case only happens when building for development while True: if self.source_path is None: source = input('Enter the full path to the Source folder: ') @@ -136,37 +132,35 @@ class BuildDriver(object): print('Start building PHP with the extension...') - self.util.build_drivers(self.make_clean, dest, logfile) + # If not testing, dest should be the root drive. Otherwise, dest should be None. + dest = None if self.testing else root_dir - if dest is None: - # This indicates the script is NOT running locally, and that - # the drivers should be in the working directory + # ext_dir is the directory where we can find the built extension(s) + ext_dir = self.util.build_drivers(self.make_clean, dest, logfile) - # Make sure drivers path is defined - if self.remote_path is None: - print('Errors: Drivers destination should be defined! Doing nothing.') - else: - dest_drivers = os.path.join(self.remote_path, self.util.major_version(), self.util.arch) - dest_symbols = os.path.join(dest_drivers, 'Symbols', self.util.thread) + # Copy the binaries if a destination path is defined + if self.dest_path is not None: + dest_drivers = os.path.join(self.dest_path, self.util.major_version(), self.util.arch) + dest_symbols = os.path.join(dest_drivers, 'Symbols', self.util.thread) + + # All intermediate directories will be created in order to create the leaf directory + if os.path.exists(dest_symbols) == False: + os.makedirs(dest_symbols) - # All intermediate directories will be created in order to create the leaf directory - if os.path.exists(dest_symbols) == False: - os.makedirs(dest_symbols) - - # Now copy all the binaries - if self.util.driver == 'all': - self.util.copy_binary(work_dir, dest_drivers, 'sqlsrv', '.dll') - self.util.copy_binary(work_dir, dest_symbols, 'sqlsrv', '.pdb') - self.util.copy_binary(work_dir, dest_drivers, 'pdo_sqlsrv', '.dll') - self.util.copy_binary(work_dir, dest_symbols, 'pdo_sqlsrv', '.pdb') - else: - self.util.copy_binary(work_dir, dest_drivers, self.util.driver, '.dll') - self.util.copy_binary(work_dir, dest_symbols, self.util.driver, '.pdb') - + # Now copy all the binaries + if self.util.driver == 'all': + self.util.copy_binary(ext_dir, dest_drivers, 'sqlsrv', '.dll') + self.util.copy_binary(ext_dir, dest_symbols, 'sqlsrv', '.pdb') + self.util.copy_binary(ext_dir, dest_drivers, 'pdo_sqlsrv', '.dll') + self.util.copy_binary(ext_dir, dest_symbols, 'pdo_sqlsrv', '.pdb') + else: + self.util.copy_binary(ext_dir, dest_drivers, self.util.driver, '.dll') + self.util.copy_binary(ext_dir, dest_symbols, self.util.driver, '.pdb') + def build(self): """This is the main entry point of building drivers for PHP. - For local builds, this will loop till the user decides to quit. + For development, this will loop till the user decides to quit. """ self.show_config() @@ -175,27 +169,23 @@ class BuildDriver(object): quit = False while not quit: - if not self.rebuild and self.local: + if not self.rebuild and not self.testing: self.clean_or_remove(root_dir, work_dir) logfile = self.util.get_logfile_name() try: - dest = None - if self.local: - dest = root_dir - - self.build_extensions(dest, logfile) + self.build_extensions(root_dir, logfile) print('Build Completed') except: print('Something went wrong, launching log file', logfile) - if self.local: # display log file only when building locally + # display log file only when not testing + if not self.testing: os.startfile(os.path.join(root_dir, 'php-sdk', logfile)) os.chdir(work_dir) break - # Only ask when building locally - if self.local: + if not self.testing: choice = input("Rebuild using the same configuration(yes) or quit (no) [yes/no]: ") choice = choice.lower() if choice == 'yes' or choice == 'y' or choice == '': @@ -226,15 +216,16 @@ def validate_input(question, values): ################################### Main Function ################################### if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('-v', '--PHPVER', help="PHP version, e.g. 7.1.*, 7.2.* etc.") - parser.add_argument('-a', '--ARCH', choices=['x64', 'x86']) - parser.add_argument('-t', '--THREAD', choices=['nts', 'ts']) - parser.add_argument('-d', '--DRIVER', default='all', choices=['all', 'sqlsrv', 'pdo_sqlsrv'], help="driver to build (default: all)") - parser.add_argument('-m', '--DEBUG', default='no', choices=['yes', 'no'], help="enable debug mode (default: no)") - parser.add_argument('-r', '--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)") - parser.add_argument('-b', '--BRANCH', default='dev', help="GitHub repository branch (default: dev)") - parser.add_argument('-g', '--GITHUB', default='yes', choices=['yes', 'no'], help="get source from GitHub (default: yes)") - parser.add_argument('-p', '--DESTPATH', default=None, help="an alternative destination for the drivers (default: None)") + parser.add_argument('--PHPVER', help="PHP version, e.g. 7.1.*, 7.2.* etc.") + parser.add_argument('--ARCH', choices=['x64', 'x86']) + parser.add_argument('--THREAD', choices=['nts', 'ts']) + parser.add_argument('--DRIVER', default='all', choices=['all', 'sqlsrv', 'pdo_sqlsrv'], help="driver to build (default: all)") + parser.add_argument('--DEBUG', action='store_true', help="enable debug mode (default: False)") + parser.add_argument('--REPO', default='Microsoft', help="GitHub repository (default: Microsoft)") + parser.add_argument('--BRANCH', default='dev', help="GitHub repository branch (default: dev)") + parser.add_argument('--SOURCE', action='store_true', help="get source from a local path (default: False)") + parser.add_argument('--TESTING', action='store_true', help="turns on testing mode (default: False)") + parser.add_argument('--DESTPATH', default=None, help="an alternative destination for the drivers (default: None)") args = parser.parse_args() @@ -242,21 +233,31 @@ if __name__ == '__main__': arch = args.ARCH thread = args.THREAD driver = args.DRIVER - debug = args.DEBUG == 'yes' + debug = args.DEBUG repo = args.REPO branch = args.BRANCH - download = args.GITHUB.lower() == 'yes' + download = args.SOURCE is False path = args.DESTPATH + testing = args.TESTING if phpver is None: - # assuming it is building drivers locally when required to prompt - # thus will not prompt for drivers' destination path, which is None by default - phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") + # starts interactive mode, testing mode is False + # will not prompt for drivers' destination path, which is None by default + while True: + # perform some minimal checks + phpver = input("PHP Version (e.g. 7.1.* or 7.2.*): ") + if phpver == '': + print('Empty PHP version entered! Please try again.') + elif phpver[0] < '7': + print('Only PHP 7.0 or above is supported. Please try again.') + else: + break + arch_version = input("64-bit? [y/n]: ") thread = validate_input("Thread safe? ", "nts/ts") driver = validate_input("Driver to build? ", "all/sqlsrv/pdo_sqlsrv") debug_mode = input("Debug enabled? [y/n]: ") - + answer = input("Download source from a GitHub repo? [y/n]: ") download = False if answer == 'yes' or answer == 'y' or answer == '': @@ -282,5 +283,6 @@ if __name__ == '__main__': repo, branch, download, - path) + path, + testing) builder.build() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index d527febb..2176b94e 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -414,7 +414,8 @@ class BuildUtil(object): self.rename_binaries(sdk_dir) # Final step, copy the binaries to the right place - self.copy_binaries(sdk_dir, copy_to_ext) + ext_dir = self.copy_binaries(sdk_dir, copy_to_ext) + return ext_dir def rename_binary(self, path, driver): """Rename the *driver* binary (sqlsrv or pdo_sqlsrv) (only the dlls).""" @@ -470,4 +471,6 @@ class BuildUtil(object): else: self.copy_binary(build_dir, dest_dir, self.driver, '.dll') self.copy_binary(build_dir, dest_dir, self.driver, '.pdb') + + return dest_dir From c371d3c29b8551ec66d435547f45bddf09bbd08b Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 21 Aug 2017 09:24:10 -0700 Subject: [PATCH 85/87] Moved compile in Windows instructions to README in buildscripts --- README.md | 17 +++-------------- buildscripts/README.md | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f877f5b3..78f2cb43 100644 --- a/README.md +++ b/README.md @@ -47,23 +47,12 @@ Note: if you prefer, you can use the pre-compiled binary found [HERE](https://gi #### 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. +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 in 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. +The Microsoft Drivers for PHP for SQL Server have been compiled and tested with PHP 7.0.* and 7.1.* using Visual C++ 2015 as well as PHP 7.2.0 beta using Visual C++ 2017 v15.0. +For details, please read the documentation and/or take a look at the sample [build scripts](https://github.com/Microsoft/msphpsql/tree/dev/buildscripts#windows). ## Install (Windows) diff --git a/buildscripts/README.md b/buildscripts/README.md index 3a533c27..8f4a98ab 100644 --- a/buildscripts/README.md +++ b/buildscripts/README.md @@ -3,16 +3,18 @@ ## Prerequisites To build extensions for - * PHP 7.0* or PHP 7.1*, install Visual Studio 2015 and make sure C++ tools are enabled. - * PHP 7.2*, install Visual Studio 2017, including Visual C++ toolset, the Windows SDK components, and Git for Windows. +1. PHP 7.0* or PHP 7.1* + * install Visual Studio 2015 and make sure C++ tools are enabled. +2. PHP 7.2* + * install Visual Studio 2017, including Visual C++ toolset and the Windows SDK components. -To use the sample build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x in Windows. +To use the sample build scripts `builddrivers.py` and `buildtools.py`, install Python 3.x and Git for Windows (which comes with Visual Studio 2017). If `git` is unrecognized in a regular command prompt, make sure the environment path is set up correctly. ## Compile the drivers -You must first be able to build PHP 7.* without including these extensions. For help with doing this, see the [official PHP website](https://wiki.php.net/internals/windows/stepbystepbuild) for building PHP 7.0* or PHP 7.1* on Windows or [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for the new instructions for building PHP 7.2 and/or above. +You must first be able to build PHP 7.* without including our PHP extensions. For help with building PHP 7.0* or PHP 7.1* in Windows, see the [official PHP website](https://wiki.php.net/internals/windows/stepbystepbuild). For PHP 7.2 or above, visit [PHP SDK page](https://github.com/OSTC/php-sdk-binary-tools) for new instructions. -The Microsoft Drivers for PHP for SQL Server have been compiled and tested with PHP 7.0.* and 7.1.* using the Visual C++ 2015 as well as PHP 7.2.0 beta using the Visual C++ 2017 v15.0. +The Microsoft Drivers for PHP for SQL Server have been compiled and tested with PHP 7.0.* and 7.1.* using Visual C++ 2015 as well as PHP 7.2.0 beta using Visual C++ 2017 v15.0. ### Manually building from source @@ -20,7 +22,7 @@ The Microsoft Drivers for PHP for SQL Server have been compiled and tested with 2. Make a copy of the *shared* folder as a subfolder in *sqlsrv* and/or *pdo_sqlsrv* folder -3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder(s) into the PHP source ext subdirectory +3. Copy the *sqlsrv* and/or *pdo_sqlsrv* folder(s) into the PHP source *ext* subdirectory 4. Run `buildconf --force` to rebuild the configure.js script to include the *sqlsrv* and/or *pdo_sqlsrv* driver(s). @@ -33,19 +35,19 @@ The Microsoft Drivers for PHP for SQL Server have been compiled and tested with 7. To install the drivers, there are two ways: * Run `nmake install`, or * Copy the drivers: - * Find the directory where the newly compiled `php.exe` is - * Locate the compiled php_sqlsrv.dll and/or php_pdo_sqlsrv.dll - * Copy the dll(s) to the `ext` subfolder + * Find the directory where the newly compiled *php.exe* is + * Locate the compiled *php_sqlsrv.dll* and/or *php_pdo_sqlsrv.dll* + * Copy the dll(s) to the *ext* subfolder ### Using the sample build scripts -The sample build scripts, `builddrivers.py` and `buildtools.py`, are expected to build our extensions for PHP in Windows. +The sample build scripts, `builddrivers.py` and `buildtools.py`, can be used to build our extensions for PHP in Windows. #### Overview -When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC version, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you should enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. +When asked to provide the PHP version, you should enter values like `7.1.7`. If it's alpha, beta, or RC version, make sure the name you provide matches the PHP tag name without the prefix `php-`. For example, for PHP 7.2 beta 2, the tag name is `php-7.2.0beta2`, so you will enter `7.2.0beta2`. Visit [PHP SRC]( https://github.com/php/php-src) to find the appropriate tag names. -PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will by default create a `php-sdk` folder in the C:\ drive, and this `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. +PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably somewhere near the root drive. Therefore, this script will, by default, create a `php-sdk` folder in the C:\ drive, and this `php-sdk` directory tree will remain unless you remove it yourself. For ongoing development, we suggest you keep it around. The build scripts will handle updating the PHP SDK if a new version is available. #### Steps @@ -54,7 +56,7 @@ PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably 2. Change to the directory where the Python scripts `builddrivers.py` and `buildtools.py` are 3. Interactive mode: - * Run `py builddrivers.py` to use the interactive mode. Use lower cases to answer the following questions: + * Type `py builddrivers.py` to start the interactive mode. Use lower cases to answer the following questions: * PHP Version (e.g. `7.1.7` or `7.2.0beta2`) * 64-bit? * Thread safe? @@ -64,7 +66,7 @@ PHP recommends to unzip the PHP SDK into the shortest possible path, preferrably * For `yes/no` questions, you can simply hit `ENTER` key for `yes`. Other questions are self-explanatory. 4. Use Command-line arguments - * Run `py builddrivers.py -h` to get a list of options and their descriptions + * Type `py builddrivers.py -h` to get a list of options and their descriptions * For example, * `py builddrivers.py --PHPVER=7.0.22 --ARCH=x64 --THREAD=nts --DRIVER=sqlsrv --SOURCE` * `py builddrivers.py --PHPVER=7.1.8 --ARCH=x86 --THREAD=ts --DEBUG` From e5f0690f3c4579c33100475c54c6649f3db5e122 Mon Sep 17 00:00:00 2001 From: Hadis Fard Date: Mon, 21 Aug 2017 15:22:17 -0700 Subject: [PATCH 86/87] added docker stats --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c290dccf..187d7f28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ before_script: script: - travis_retry docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --name=client --link $TEST_PHP_SQL_SERVER msphpsql-dev - docker ps -a + - docker stats - docker logs client - travis_retry docker exec client python ./test/functional/setup/setup_dbs.py -dbname $SQLSRV_DBNAME - travis_retry docker exec client python ./test/functional/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME From 22a5034c7d71e15aaee1f0df276d60847281c5c6 Mon Sep 17 00:00:00 2001 From: v-susanh Date: Mon, 21 Aug 2017 15:46:39 -0700 Subject: [PATCH 87/87] updated scripts to take pre-compiled driver binaries (#504) * updated scripts to take pre-compiled driver binaries --- test/Performance/README.md | 39 ++-- test/Performance/compile_php.bat | 3 - test/Performance/setup_env_unix.sh | 242 +++++++++++++++---------- test/Performance/setup_env_windows.ps1 | 110 ++++------- 4 files changed, 197 insertions(+), 197 deletions(-) delete mode 100644 test/Performance/compile_php.bat diff --git a/test/Performance/README.md b/test/Performance/README.md index deb0e34b..d58b49e7 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -1,26 +1,30 @@ ## Setup Environment on a clean machine -### Windows -Install Visual Studio 2015 before running the following commands. Make sure C++ tools are enabled. -Run `cmd` as administrator. +The PHP zip file can be downloaded from . + +The SQLSRV and PDO_SQLSRV driver binaries can be downloaded from . + +### Windows +Install Visual Studio 2015 redistributable before running the following commands. +Run `Windows PowerShell` as administrator. - powershell Set-ExecutionPolicy Unrestricted - .\setup_env_windows.ps1 + .\setup_env_windows.ps1 ### Ubuntu 16 - sudo env "PATH=$PATH" bash setup_env_unix.sh Ubuntu16 + sudo env "PATH=$PATH" bash setup_env_unix.sh Ubuntu16 ### RedHat 7 - sudo env "PATH=$PATH" bash setup_env_unix.sh RedHat7 -### Sierra + sudo env "PATH=$PATH" bash setup_env_unix.sh RedHat7 +### MacOS 10.12 Sierra `brew` cannot be run with `sudo` on Sierra. Either enable passwordless `sudo` on the machine or enter the password when prompted. - bash setup_env_unix.sh Sierra + bash setup_env_unix.sh Sierra ## Run benchmarks PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/latest/introduction.html to have an idea how the tool works. -### 1. Modify lib/connect.php with the test database credentials -### 2. Execute run-perf_tests.py. +##### 1. Modify lib/connect.php with the test database credentials +##### 2. Execute run-perf_tests.py + ### Windows py.exe run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd -iterations -iterations-large -result-server -result-db -result-uid -result-pwd -`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016 WindowsServer2012 Ubuntu16 RedHat7 Sierra +`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra. `-iterations` - The number of iterations for regular tests. `-iterations-large` - The number of iterations for the tests that fetch large data. Usually set to 1. -`-result-server` - The server of result database. It is assumed that, the result database already setup before running the tests. -`-result-db` - Database name. With the current result database setup files, this should be set to `TestResults` -`-result-uid` - Result database username -`-result-pwd` Result database password - - - +`-result-server` - The server containing the result database. It is assumed that the result database s already setup before running the tests. +`-result-db` - Database name. With the current result database setup files, this should be set to `TestResults`. +`-result-uid` - Result database username. +`-result-pwd` - Result database password. diff --git a/test/Performance/compile_php.bat b/test/Performance/compile_php.bat deleted file mode 100644 index e08b0f3a..00000000 --- a/test/Performance/compile_php.bat +++ /dev/null @@ -1,3 +0,0 @@ -set options=%2 -set options=%options:"=% -C:\php-sdk\bin\phpsdk_setvars.bat && "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %1 && .\buildconf --force && .\configure %options% && nmake && nmake install \ No newline at end of file diff --git a/test/Performance/setup_env_unix.sh b/test/Performance/setup_env_unix.sh index e8a139dc..a2f51cb0 100644 --- a/test/Performance/setup_env_unix.sh +++ b/test/Performance/setup_env_unix.sh @@ -1,140 +1,190 @@ #!/bin/bash + set -e + if [[ ("$1" = "Ubuntu16" || "$1" = "RedHat7" || "$1" = "Sierra") ]]; then PLATFORM=$1 else - echo "First argument must be one of Ubuntu16, RedHat7, Sierra. Exiting..." + echo "1st argument must be one of Ubuntu16, RedHat7, Sierra. Exiting..." exit 1 fi + if [[ "$2" != 7.*.* ]]; then - echo "Second argument must be PHP version in format of 7.x.x.Exiting..." + echo "2nd argument must be PHP version in format of 7.x.y. Exiting..." exit else PHP_VERSION=$2 fi + if [[ ("$3" != "nts" && "$3" != "ts") ]]; then - echo "Thrid argument must be either nts or ts. Exiting..." + echo "3rd argument must be either nts or ts. Exiting..." exit 1 else PHP_THREAD=$3 fi -if [[ (! -d "$4") || (! -d $4/sqlsrv) || (! -d $4/pdo_sqlsrv) || (! -d $4/shared) ]]; then - echo "Fourth argument must be path to source folder.Path not found.Exiting..." + +if [[ (! -f "$4") || (! -f "$5") ]]; then + echo "5th and 6th argument must be paths to sqlsrv and pdo drivers. Exiting..." exit 1 else - DRIVER_SOURCE_PATH=$4 + SQLSRV_DRIVER=$4 + PDO_DRIVER=$5 fi -rm -rf env_setup.log -touch env_setup.log + if [ $PLATFORM = "Ubuntu16" ]; then - echo "Update..." - yes | sudo dpkg --configure -a >> env_setup.log 2>&1 - yes | sudo apt-get update >> env_setup.log 2>&1 - echo "Installing git, zip, curl, libxml, autoconf, openssl, python3, pip3..." - yes | sudo apt-get install git zip curl autoconf libxml2-dev libssl-dev pkg-config python3 python3-pip >> env_setup.log 2>&1 - echo "OK" - echo "Installing MSODBCSQL..." + printf "Update..." + yes | sudo dpkg --configure -a > env_setup.log + yes | sudo apt-get update >> env_setup.log + printf "done\n" + + printf "Installing git, zip, curl, libxml, autoconf, openssl, python3, pip3..." + yes | sudo apt-get install git zip curl autoconf libxml2-dev libssl-dev pkg-config python3 python3-pip >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." curl -s https://packages.microsoft.com/keys/microsoft.asc | apt-key add - curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list - yes | sudo apt-get update >> env_setup.log 2>&1 - yes | sudo ACCEPT_EULA=Y apt-get install msodbcsql >> env_setup.log 2>&1 - yes | sudo apt-get install -qq unixodbc-dev >> env_setup.log 2>&1 - echo "Installing pyodbc" - pip3 install --upgrade pip >> env_setup.log 2>&1 - pip3 install pyodbc >> env_setup.log 2>&1 - echo "OK" + yes | sudo apt-get update >> env_setup.log + yes | sudo ACCEPT_EULA=Y apt-get install msodbcsql >> env_setup.log + yes | sudo apt-get install -qq unixodbc-dev >> env_setup.log + printf "done\n" + + printf "Installing pyodbc" + pip3 install --upgrade pip >> env_setup.log + pip3 install pyodbc >> env_setup.log + printf "done\n" + elif [ $PLATFORM = "RedHat7" ]; then - echo "Update..." - yes | sudo yum update >> env_setup.log 2>&1 - echo "OK" - echo "Enabling EPEL repo..." + printf "Update..." + yes | sudo yum update >> env_setup.log + printf "done\n" + + printf "Enabling EPEL repo..." +# pipe non-error to log file (wget and yum install reports error when there's nothing to do) wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm >> env_setup.log 2>&1 yes | sudo yum install epel-release-latest-7.noarch.rpm >> env_setup.log 2>&1 || true - echo "OK" - echo "Installing python34-setuptools..." - yes | sudo yum install python34-setuptools -y >> env_setup.log 2>&1 - echo "OK" - echo "Installing gcc, git, zip libxml, openssl, EPEL, python3, pip3..." - yes | sudo yum install -y gcc-c++ libxml2-devel git zip openssl-devel python34 python34-devel python34-pip >> env_setup.log 2>&1 - echo "OK" - echo "Installing MSODBCSQL..." + printf "done\n" + + printf "Installing python34-setuptools..." + yes | sudo yum install python34-setuptools -y >> env_setup.log + printf "done\n" + + printf "Installing gcc, git, zip libxml, openssl, EPEL, python3, pip3..." + yes | sudo yum install -y gcc-c++ libxml2-devel git zip openssl-devel python34 python34-devel python34-pip >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." curl -s https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo - (yes | sudo ACCEPT_EULA=Y yum install -y msodbcsql >> env_setup.log 2>&1) - (yes | sudo yum install -y unixODBC-devel autoconf >> env_setup.log 2>&1) - echo "OK" - echo "Installing pyodbc" - pip3 install --upgrade pip >> env_setup.log 2>&1 - pip3 install pyodbc >> env_setup.log 2>&1 - echo "OK" + (yes | sudo ACCEPT_EULA=Y yum install -y msodbcsql >> env_setup.log) + (yes | sudo yum install -y unixODBC-devel autoconf >> env_setup.log) + printf "done\n" + + printf "Installing pyodbc" + pip3 install --upgrade pip >> env_setup.log + pip3 install pyodbc >> env_setup.log + printf "done\n" + elif [ $PLATFORM = "Sierra" ]; then - echo "Installing homebrew..." - yes | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" >> env_setup.log 2>&1 - echo "OK" - echo "Installing wget..." - brew install wget >> env_setup.log 2>&1 - echo "OK" - echo "Installing svn..." - brew install svn >> env_setup.log 2>&1 - echo "OK" - echo "Installing openssl..." - brew install pkg-config >> env_setup.log 2>&1 - brew install openssl >> env_setup.log 2>&1 - echo "OK" - echo "Installing python3..." - brew install python3 >> env_setup.log 2>&1 - echo "OK" - echo "Installing MSODBCSQL..." - brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-msodbcsql >> env_setup.log 2>&1 - brew update >> env_setup.log 2>&1 - yes | ACCEPT_EULA=Y brew install msodbcsql >> env_setup.log 2>&1 - echo "OK" - yes | brew install autoconf >> env_setup.log 2>&1 - echo "Installing pyodbc..." - pip3 install pyodbc >> env_setup.log 2>&1 - echo "OK" + printf "Installing homebrew..." + yes | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" >> env_setup.log + printf "done\n" + + printf "Installing wget..." + brew install wget >> env_setup.log + printf "done\n" + + printf "Installing svn..." + brew install svn >> env_setup.log + printf "done\n" + + printf "Installing openssl..." + brew install pkg-config >> env_setup.log + brew install openssl >> env_setup.log + printf "done\n" + + printf "Installing python3..." + brew install python3 >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." + brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-msodbcsql >> env_setup.log + brew update >> env_setup.log + yes | ACCEPT_EULA=Y brew install --no-sandbox msodbcsql >> env_setup.log + printf "done\n" + + yes | brew install autoconf >> env_setup.log + printf "Installing pyodbc..." + pip3 install pyodbc >> env_setup.log + printf "done\n" fi -echo "Downloading PHP-$PHP_VERSION source tarball..." + +printf "Downloading PHP-$PHP_VERSION source tarball..." +# pipe non-error to log file wget http://ca1.php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror -O php-$PHP_VERSION.tar.gz >> env_setup.log 2>&1 -echo "OK" -echo "Extracting PHP source tarball..." +printf "done\n" + +printf "Extracting PHP source tarball..." rm -rf php-$PHP_VERSION tar -xf php-$PHP_VERSION.tar.gz -echo "OK" -cd php-$PHP_VERSION -mkdir ext/sqlsrv ext/pdo_sqlsrv -cp -r $DRIVER_SOURCE_PATH/sqlsrv/* $DRIVER_SOURCE_PATH/shared ext/sqlsrv -cp -r $DRIVER_SOURCE_PATH/pdo_sqlsrv/* $DRIVER_SOURCE_PATH/shared ext/pdo_sqlsrv +printf "done\n" + +phpDir=php-$PHP_VERSION +cd $phpDir + +printf "Configuring PHP..." ./buildconf --force >> ../env_setup.log 2>&1 -CONFIG_OPTIONS="--enable-cli --enable-cgi --enable-pdo --enable-sqlsrv=shared --with-pdo_sqlsrv=shared --with-odbcver=0x0380 --with-zlib --enable-mbstring --prefix=/usr/local" +CONFIG_OPTIONS="--enable-cli --enable-cgi --with-zlib --enable-mbstring --prefix=/usr/local" [ "${PHP_THREAD}" == "ts" ] && CONFIG_OPTIONS=${CONFIG_OPTIONS}" --enable-maintainer-zts" if [ $PLATFORM = "Sierra" ]; then CONFIG_OPTIONS=$CONFIG_OPTIONS" --with-openssl=/usr/local/opt/openssl/" else CONFIG_OPTIONS=$CONFIG_OPTIONS" --with-openssl" fi -echo "Configuring PHP..." +#pipe non-error to log file (./configure $CONFIG_OPTIONS >> ../env_setup.log 2>&1) -echo "OK" -echo "Compiling PHP and the drivers..." -make >> ../env_setup.log 2>&1 -echo "OK" -sudo make install >> ../env_setup.log 2>&1 +printf "done\n" + +printf "Compiling and installing PHP..." +make >> ../env_setup.log +sudo make install >> ../env_setup.log +printf "done\n" + +# check PHP version +/usr/local/bin/php -v + +printf "Setting up drivers..." +phpExtDir=`/usr/local/bin/php-config --extension-dir` cp php.ini-production php.ini -echo "extension=sqlsrv.so" >> php.ini -echo "extension=pdo_sqlsrv.so" >> php.ini +driverName=$(basename $SQLSRV_DRIVER) +echo "extension=$driverName" >> php.ini +sudo cp -r $SQLSRV_DRIVER $phpExtDir/$driverName +sudo chmod a+r $SQLSRV_DRIVER $phpExtDir/$driverName + +driverName=$(basename $PDO_DRIVER) +echo "extension=$driverName" >> php.ini +sudo cp -r $PDO_DRIVER $phpExtDir/$driverName +sudo chmod a+r $SQLSRV_DRIVER $phpExtDir/$driverName + sudo cp php.ini /usr/local/lib +printf "done\n" + +# check drivers +/usr/local/bin/php --ri sqlsrv +/usr/local/bin/php --ri pdo_sqlsrv + +printf "Installing Composer..." cd .. -php -v -php --ri sqlsrv -php --ri pdo_sqlsrv -echo "Installing Composer..." +# pipe non-error to log file wget https://getcomposer.org/installer -O composer-setup.php >> env_setup.log 2>&1 -php composer-setup.php >> env_setup.log 2>&1 -echo "OK" -echo "Installing PHPBench..." -php composer.phar install >> env_setup.log 2>&1 -echo "OK" -echo "Cleaning up..." -rm -rf php-$PHP_VERSION* compser-setup.php -echo "OK" -echo "Setup completed!" \ No newline at end of file +/usr/local/bin/php composer-setup.php >> env_setup.log +printf "done\n" + +printf "Installing PHPBench...\n" +/usr/local/bin/php composer.phar install >> env_setup.log +printf "done\n" + +printf "Cleaning up..." +rm -rf $phpDir compser-setup.php +printf "done\n" + +echo "Setup completed!" diff --git a/test/Performance/setup_env_windows.ps1 b/test/Performance/setup_env_windows.ps1 index c4a580e5..a6b83633 100644 --- a/test/Performance/setup_env_windows.ps1 +++ b/test/Performance/setup_env_windows.ps1 @@ -1,28 +1,13 @@ Param( [Parameter(Mandatory=$True,Position=1)] - [string]$PHP_VERSION, - [Parameter(Mandatory=$True,Position=2)] - [string]$PHP_THREAD, + [string]$PHP_ZIP, + [Parameter(Mandatory=$True,Position=2)] + [string]$SQLSRV_DRIVER, [Parameter(Mandatory=$True,Position=3)] - [string]$DRIVER_SOURCE_PATH, -[Parameter(Mandatory=$True,Position=4)] - [string]$ARCH + [string]$PDO_DRIVER ) -IF($ARCH -ne "x64" -And $ARCH -ne "x86"){ - Write-Host "ARCH must either x64 or x86" - Break -} - -IF($PHP_THREAD -ne "nts" -And $PHP_THREAD -ne "ts"){ - Write-Host "PHP_THREAD must either nts or ts" - Break -} - -IF($PHP_VERSION -NotMatch "7.[0-1].[0-9]"){ - Write-Host "PHP_VERSION must be in format of 7.x.x" - Break -} +$ErrorActionPreference = "Stop" $startingDir=$pwd.Path $tempFolder=Join-Path $startingDir "temp" @@ -30,17 +15,12 @@ $tempFolder=Join-Path $startingDir "temp" Remove-Item temp -Recurse -Force -ErrorAction Ignore New-Item -ItemType directory -Path temp -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/sha1sum.txt","$tempFolder\sha1sum.txt") -$PHP70_LATEST_VERSION=type $tempFolder\sha1sum.txt | where { $_ -match "php-(7.0\.\d+)-src" } | foreach { $matches[1] } -$PHP71_LATEST_VERSION=type $tempFolder\sha1sum.txt | where { $_ -match "php-(7.1\.\d+)-src" } | foreach { $matches[1] } - -$PHP_VERSION_MINOR=$PHP_VERSION.split(".")[1] - Write-Host "Installing chocolatey..." iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) Write-Host "Installing Git..." choco install -y git -Set-Alias git 'C:\Program Files\Git\cmd\git.exe' + +$gitDir = 'C:\Program Files\Git\cmd\git.exe' Write-Host "Installing Python3..." choco install -y python3 RefreshEnv @@ -54,65 +34,37 @@ msiexec /quiet /passive /qn /i $tempFolder\msodbcsql.msi IACCEPTMSODBCSQLLICENSE Write-Host "Installing 7-Zip..." choco install -y 7zip.install -Write-Host "Downloading PHP-SDK..." -(New-Object System.Net.WebClient).DownloadFile('http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip', "$tempFolder\binary_tools.zip") -Write-Host "Downloading PHP-$PHP_VERSION source..." -IF($PHP_VERSION -eq $PHP70_LATEST_VERSION -Or $PHP_VERSION -eq $PHP71_LATEST_VERSION){ -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/php-$PHP_VERSION-src.zip", "$tempFolder\php-$PHP_VERSION-src.zip") -} -ELSE{ -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/archives/php-$PHP_VERSION-src.zip", "$tempFolder\php-$PHP_VERSION-src.zip") -} +Write-Host "Installing PHP..." +$phpDir="C:\php" -Write-Host "Downloading Dependencies..." -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/php-sdk/deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z", "$tempFolder\deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z") +# remove existing PHP and setup new one +Remove-Item $phpDir -Recurse -ErrorAction Ignore +New-Item -ItemType directory -Path $phpDir +Expand-Archive $PHP_ZIP -DestinationPath $phpDir +Copy-Item $SQLSRV_DRIVER $phpDir\ext +Copy-Item $PDO_DRIVER $phpDir\ext -Add-Type -AssemblyName System.IO.Compression.FileSystem -Remove-Item C:\php-sdk -Recurse -Force -ErrorAction Ignore -New-Item -ItemType directory -Path C:\php-sdk -[System.IO.Compression.ZipFile]::ExtractToDirectory("$tempFolder\binary_tools.zip", "C:\php-sdk") -cd C:\php-sdk\ -bin\phpsdk_buildtree.bat phpdev -New-Item -ItemType directory -Path .\phpdev\vc14 -Copy-Item .\phpdev\vc9\* phpdev\vc14\ -recurse -[System.IO.Compression.ZipFile]::ExtractToDirectory("$tempFolder\php-$PHP_VERSION-src.zip", "C:\php-sdk\phpdev\vc14\$ARCH\") -7z.exe x $tempFolder\deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z -oC:\php-sdk\phpdev\vc14\$ARCH\ +# setup driver +Copy-Item $phpDir\php.ini-production $phpDir\php.ini +Add-Content $phpDir\php.ini "extension=$phpDir\ext\php_openssl.dll" +Add-Content $phpDir\php.ini "extension=$phpDir\ext\php_mbstring.dll" -bin\phpsdk_setvars.bat - -cd C:\php-sdk\phpdev\vc14\$ARCH\php-$PHP_VERSION-src - -New-Item -ItemType directory -Path .\ext\sqlsrv -New-Item -ItemType directory -Path .\ext\pdo_sqlsrv -Copy-Item $DRIVER_SOURCE_PATH\sqlsrv\* .\ext\sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\shared\ .\ext\sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\pdo_sqlsrv\* .\ext\pdo_sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\shared\ .\ext\pdo_sqlsrv\ -recurse - - -$CONFIG_OPTIONS="--enable-cli --enable-cgi --enable-sqlsrv=shared --enable-pdo=shared --with-pdo-sqlsrv=shared --with-odbcver=0x0380 --enable-mbstring --with-openssl" -if ($PHP_THREAD -ceq "nts") { - $CONFIG_OPTIONS=$CONFIG_OPTIONS + " --disable-zts" -} -& $startingDir\compile_php.bat $ARCH $CONFIG_OPTIONS - - - - -Copy-Item php.ini-production php.ini -Add-Content php.ini "extension=C:\php\ext\php_sqlsrv.dll" -Add-Content php.ini "extension=C:\php\ext\php_pdo_sqlsrv.dll" -Add-Content php.ini "extension=C:\php\ext\php_openssl.dll" -Move-Item php.ini C:\Windows -force -Copy-Item C:\php-sdk\phpdev\vc14\$ARCH\deps\bin\ssleay32.dll C:\Windows -force -Copy-Item C:\php-sdk\phpdev\vc14\$ARCH\deps\bin\libeay32.dll C:\Windows -force +$driverName=Split-Path $SQLSRV_DRIVER -leaf +Add-Content $phpDir\php.ini "extension=$phpDir\ext\$driverName" +$driverName=Split-Path $PDO_DRIVER -leaf +Add-Content $phpDir\php.ini "extension=$phpDir\ext\$driverName" +Move-Item $phpDir\php.ini C:\Windows -force +Copy-Item $phpDir\ssleay32.dll C:\Windows -force +Copy-Item $phpDir\libeay32.dll C:\Windows -force cd $startingDir -[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\php\", [System.EnvironmentVariableTarget]::Machine) -$env:Path += ";C:\php\" +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";" + $phpDir + ";" + $gitDir, [System.EnvironmentVariableTarget]::Machine) +$env:Path = $env:Path + ";" + $phpDir + ";" + $gitDir RefreshEnv + +# setup composer wget https://getcomposer.org/installer -O composer-setup.php php composer-setup.php php composer.phar install Remove-Item temp -Recurse -Force -ErrorAction Ignore -Write-Host "Setup completed!" \ No newline at end of file +Write-Host "Setup completed!"