Go to file
2016-12-19 15:12:10 -08:00
ODBC install scripts Update installodbc_ubuntu.sh 2016-10-18 15:08:47 -07:00
sample 4.0.1 Release 2016-07-12 11:50:10 -07:00
source upgraded to 4.0.8 2016-12-16 18:16:52 -08:00
test Docker image, TravisCI, tests 2016-12-15 15:56:31 -08:00
.travis.yml Clean up 2016-12-16 11:18:59 -08:00
CHANGELOG.md release 4.0.8 changelog 2016-12-19 15:12:10 -08:00
Dockerfile-msphpsql Removing some comments 2016-12-16 11:25:32 -08:00
LICENSE 4.0.1 Release 2016-07-12 11:50:10 -07:00
LinuxTutorial.md Update LinuxTutorial.md 2016-12-05 15:12:40 -08:00
README.md updated announcements 2016-12-19 14:19:11 -08:00

Microsoft Drivers for PHP for SQL Server

Welcome to the Microsoft Drivers for PHP for SQL Server PHP 7 Linux

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 2005 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 project contains the SQLSRV and PDO_SQLSRV drivers for PHP 7 (64-bit) with limitations (see Limitations below for details). Upcoming release(s) will contain more functionality, bug fixes, and more.

SQL Server Team ###Status of Most Recent Builds

Travis CI (Linux) Coverage Status
tv-image Coverage Status

##Get Started

Install

Step 1: Install PHP (unless already installed)

Ubuntu 15.10

sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get install php7.0 php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring

Ubuntu 16.04

apt-get update
sudo apt-get -y install php7.0 mcrypt php7.0-mcrypt php-mbstring php-pear php7.0-dev 

RedHat 7

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 update
yum install php70-php

RedHat 6

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
rhn-channel --add --channel=rhel-$(uname -i)-server-optional-6
yum update
yum install php70-php

Step 2: Install pre-requisites

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-utf16 #this step is optional but recommended*

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-utf16

RedHat 6

sudo su
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum update
sudo yum remove unixODBC #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools 
sudo yum install unixODBC-utf16-devel 

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 #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools 
sudo yum install unixODBC-utf16-devel 

*Note: On Ubuntu, you need to make sure you install PHP 7 before you proceed to step 2. The Microsoft PHP Drivers for SQL Server will only work for PHP 7+.

Step 2: Install Apache

Ubuntu

sudo apt-get install libapache2-mod-php7.0 
sudo apt-get install apache2

RedHat

sudo yum install httpd

Step 3: Install the Microsoft PHP Drivers for SQL Server

sudo pecl install sqlsrv-4.0.8
sudo pecl install pdo_sqlsrv-4.0.8

Step 4: Add the Microsoft PHP Drivers for SQL Server to php.ini

Ubuntu

echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini

RedHat

echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php.ini
echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/opt/remi/php70/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/opt/remi/php70/php.ini

Step 5: Restart Apache to load the new php.ini file

Ubuntu

sudo service apache2 restart

RedHat

sudo apachectl restart 

Step 6: Create your sample app

Navigate to /var/www/html 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.

<?php
$serverName = "yourServername";
$connectionOptions = array(
    "Database" => "yourDatabase",
    "Uid" => "yourUsername",
    "PWD" => "yourPassword"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
//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()));
?> 
 <h1> Results : </h1>
 <?php
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
    echo ($row['SQL_VERSION']);
    echo ("<br/>");
}
sqlsrv_free_stmt($getResults);
function FormatErrors( $errors )  
{  
    /* Display errors. */  
    echo "Error information: <br/>";  
  
    foreach ( $errors as $error )  
    {  
        echo "SQLSTATE: ".$error['SQLSTATE']."<br/>";  
        echo "Code: ".$error['code']."<br/>";  
        echo "Message: ".$error['message']."<br/>";  
    }  
}  
?>

Step 7: Run your sample app

Go to your browser and type in http://localhost/testsql.php You should be able to connect to your SQL Server/Azure SQL Database and see the following results

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. If you wish to install Apache from source, follow these instructions:

##Announcements

December 19, 2016: We are delighted announce that production release for PHP Linux Driver for SQL Server is available. PECL packages (4.0.8) are updated with the latest changes, and Linux binaries (4.0.8) compiled with PHP 7.0.14 are available for Ubuntu 15.04, Ubuntu 16.04, and RedHat 7.2. For complete list of changes please visit CHANGELOG file.

Please visit the blog for more announcements.

Limitations

  • This preview contains the PHP 7 port of the SQLSRV and PDO_SQLSRV drivers, and does not provide backwards compatibility with PHP 5.
  • Binding output parameter using emulate prepare is not supported.
  • 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

The following items have known issues:

  • Connection pooling in PDO_SQLSRV is not supported.
  • Binary column binding with emulate prepare (issue#140)

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)?
    • 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 once they solidify over the next few weeks.

Q: What's next?

A: On July 20, 2016 we released the early technical preview for our PHP Driver. We will continue releasing frequent technical previews until we reach production quality.

Q: Is Microsoft taking pull requests for this project?

A: We will not be seeking to take pull requests until GA, Build Verification, and Fundamental tests are released. At this point Microsoft will also begin actively developing using this GitHub project as the prime repository.

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. Please note that this documentation is not yet updated for PHP 7.

Team Blog: Browse our blog for comments and announcements from the team in the team blog.

Known Issues: Please visit the project on Github to view outstanding issues and report new ones.