dd804fd0ab | ||
---|---|---|
sample | ||
source | ||
test | ||
LICENSE | ||
README.md | ||
appveyor.yml |
README.md
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 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 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).
The Microsoft Drivers for PHP for SQL Server Team
##Get Started
##Announcements
October 25 , 2016 : Updated Windows drivers (4.1.4) compiled with PHP 7.0.12 and 7.1 are available. Here is the list of updates:
- Drivers versioning has been redesigned as Major#.Minor#.Release#.Build#. Build number is specific to binaries and it doesn't match with the number on the source.
- Fixed the issue with duplicate warning messages in PDO_SQLSRV drivers when error mode is set to PDO::ERRMODE_WARNING.
October 4 , 2016 : Updated Windows drivers (4.1.3) compiled with PHP 7.0.11 and 7.1.0RC3 are available. Here is the list of updates:
- Fixed issue #139 : sqlsrv_fetch_object calls custom class constructor in static context and outputs an error.
September 9, 2016 : Updated Windows drivers (4.1.2) compiled with PHP 7.0.10 are available. Here is the list of updates:
-
Fixed issue #119 (modifying class name in sqlsrv_fetch_object).
-
Added following integer SQL Types constants for cases which function-like SQL types constants cannot be used e.g. type comparison:
SQLSRV constant Typical SQL Server data type SQL type identifier SQLSRV_SQLTYPE_DECIMAL decimal SQL_DECIMAL SQLSRV_SQLTYPE_NUMERIC numeric SQL_NUMERIC SQLSRV_SQLTYPE_CHAR char SQL_CHAR SQLSRV_SQLTYPE_NCHAR nchar SQL_WCHAR SQLSRV_SQLTYPE_VARCHAR varchar SQL_VARCHAR SQLSRV_SQLTYPE_NVARCHAR nvarchar SQL_WVARCHAR SQLSRV_SQLTYPE_BINARY binary SQL_BINARY SQLSRV_SQLTYPE_VARBINARY varbinary SQL_VARBINARY Note: These constants should be used in type comparison operations (refer to issue #87 and #99 ), and don't replace the function like constants with the similar syntax, for binding parameters you should use the function-like constants, otherwise you'll get an error.
August 22, 2016 : Updated Windows drivers(4.1.1) compiled with PHP 7.0.9 are available and include a couple of bug fixes:
- Fixed issue with storing integers in varchar field.
- Fixed issue with invalid connection handler if one connection fails.
- Fixed crash when emulate prepare is on.
July 28, 2016 (4.1.0): Thanks to the community's input, this release expands drivers functionalities and also includes some bug fixes:
SQLSRV_ATTR_FETCHES_NUMERIC_TYPE
connection attribute flag is added to PDO_SQLSRV driver to handle numeric fetches from columns with numeric Sql types (only bit, integer, smallint, tinyint, float and real). This flag can be turned on by setting its value inPDO::setAttribute
totrue
, For example,$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE,true);
IfSQLSRV_ATTR_FETCHES_NUMERIC_TYPE
is set totrue
the results from an integer column will be represented as anint
, likewise, Sql types float and real will be represented asfloat
. Note for exceptions:- When connection option flag
ATTR_STRINGIFY_FETCHES
is on, even whenSQLSRV_ATTR_FETCHES_NUMERIC_TYPE
is on, the return value will still be string. - When the returned PDO type in bind column is
PDO_PARAM_INT
, the return value from a integer column will be int even ifSQLSRV_ATTR_FETCHES_NUMERIC_TYPE
is off.
- When connection option flag
- Fixed float truncation when using buffered query.
- Fixed handling of Unicode strings and binary when emulate prepare is on in
PDOStatement::bindParam
. To bind a unicode string,PDO::SQLSRV_ENCODING_UTF8
should be set using$driverOption
, and to bind a string to column of Sql type binary,PDO::SQLSRV_ENCODING_BINARY
should be set. - Fixed string truncation in bind output parameters when the size is not set and the length of initialized variable is less than the output.
- Fixed bind string parameters as bidirectional parameters (
PDO::PARAM_INPUT_OUTPUT
) in PDO_SQLSRV driver. Note for output or bidirectional parameters,PDOStatement::closeCursor
should be called to get the output value.
Build
Note: if you prefer, you can use the pre-compiled binary found HERE
####Prerequisites
You must first be able to build PHP 7 without including these extensions. For help with doing this, see the official PHP website for building your own PHP on Windows.
####Compile the drivers
-
Copy the sqlsrv and/or pdo_sqlsrv source code directory from this repository into the ext subdirectory.
-
Run
buildconf.bat
to rebuild the configure.js script to include the driver. -
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 runconfigure.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
-
Run
nmake
. It is suggested that you run the entire build. If you wish to do so, runnmake clean
first. -
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.
Install
####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 or Microsoft ODBC Driver 13
####Enable the drivers
-
Make sure that the driver is in your PHP extension directory (you can simply copy it there if you did not use nmake install).
-
Enable it within your PHP installation's php.ini:
extension=php_sqlsrv.dll
and/orextension=php_pdo_sqlsrv.dll
. If necessary, specify the extension directory using extension_dir, for example:extension_dir = "C:\PHP\ext"
-
Restart the Web server.
Sample Code
For samples, please see the sample folder. For setup instructions, see [here] phpazure
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 parameter using emulate prepare is not supported.
Known Issues
- User defined data types and SQL_VARIANT.
- Passing custom class constructor to sqlsrv_fetch_object reproduce an error(issue#139).
- Binary column binding with emulate prepare (issue#140 )
Future Plans
- Expand SQL 16 Feature Support (example: Always Encrypted).
- Build 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
- 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 once they solidify over the next few weeks.
Q: What's next?
A: On Jan 29, 2016 we released an early technical preview for our PHP Driver and several since. We will continue to release frequently to improve the quality of our driver.
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.