Merge branch 'fix_failing_tests' of https://github.com/david-puglielli/msphpsql into fix_failing_tests

Resolved conflicts earlier without syncing this merge
This commit is contained in:
David Puglielli 2017-06-20 17:54:42 -07:00
commit efe15ee344
166 changed files with 8210 additions and 326 deletions

View file

@ -37,8 +37,6 @@ Thank you for taking time to take our February survey. Let us know how we are do
## Announcements
**March 7, 2017**: We are thrilled to announce that the early technical preview for SQLSRV and PDO_SQLSRV drivers is now available, both drivers have been built and tested on El Capitan (OS X 10.11). For complete list of changes please visit [4.1.7-preview release notes](https://github.com/Microsoft/msphpsql/releases/tag/v4.1.7-preview).
Please visit the [blog][blog] for more announcements.

View file

@ -66,3 +66,7 @@ if test "$PHP_PDO_SQLSRV" != "no"; then
PHP_ADD_BUILD_DIR([$ext_builddir/shared], 1)
fi
#if (defined __APPLE__ && defined __MACH__) \
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion` \
#endif

View file

@ -3,7 +3,7 @@
//
// Contents: JScript build configuration used by buildconf.bat
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Implements the PDO object for PDO_SQLSRV
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -57,6 +57,7 @@ const char TraceFile[] = "TraceFile";
const char TraceOn[] = "TraceOn";
const char TrustServerCertificate[] = "TrustServerCertificate";
const char TransactionIsolation[] = "TransactionIsolation";
const char TransparentNetworkIPResolution[] = "TransparentNetworkIPResolution";
const char WSID[] = "WSID";
}
@ -338,6 +339,15 @@ const connection_option PDO_CONN_OPTS[] = {
CONN_ATTR_BOOL,
pdo_bool_conn_str_func::func
},
{
PDOConnOptionNames::TransparentNetworkIPResolution,
sizeof(PDOConnOptionNames::TransparentNetworkIPResolution),
SQLSRV_CONN_OPTION_TRANSPARANT_NETWORK_IP_RESOLUTION,
ODBCConnOptions::TransparentNetworkIPResolution,
sizeof(ODBCConnOptions::TransparentNetworkIPResolution),
CONN_ATTR_STRING,
conn_str_append_func::func
},
{
PDOConnOptionNames::WSID,
sizeof( PDOConnOptionNames::WSID ),

View file

@ -3,7 +3,7 @@
//
// Contents: initialization routines for PDO_SQLSRV
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -5,7 +5,7 @@
//
// Copyright Microsoft Corporation
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Implements the PDOStatement object for the PDO_SQLSRV
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Utility functions used by both connection or statement functions
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -6,7 +6,7 @@
//
// Contents: Declarations for the extension
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Version resource
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -6,7 +6,7 @@
// Contents: Contains functions for handling Windows format strings
// and UTF-16 on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: Contains functions for handling Windows format strings
// and UTF-16 on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Contains functions for handling UTF-16 on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Contains functions for handling UTF-16 on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Core routines that use connection handles shared between sqlsrv and pdo_sqlsrv
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: common initialization routines shared by PDO and sqlsrv
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Result sets
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -6,7 +6,7 @@
//
// Contents: Core routines and constants shared by the Microsoft Drivers for PHP for SQL Server
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -1100,6 +1100,7 @@ const char TraceFile[] = "TraceFile";
const char TraceOn[] = "TraceOn";
const char TrustServerCertificate[] = "TrustServerCertificate";
const char TransactionIsolation[] = "TransactionIsolation";
const char TransparentNetworkIPResolution[] = "TransparentNetworkIPResolution";
const char WSID[] = "WSID";
const char UID[] = "UID";
const char PWD[] = "PWD";
@ -1128,6 +1129,7 @@ enum SQLSRV_CONN_OPTIONS {
SQLSRV_CONN_OPTION_APPLICATION_INTENT,
SQLSRV_CONN_OPTION_MULTI_SUBNET_FAILOVER,
SQLSRV_CONN_OPTION_AUTHENTICATION,
SQLSRV_CONN_OPTION_TRANSPARANT_NETWORK_IP_RESOLUTION,
#ifdef _WIN32
SQLSRV_CONN_OPTION_CONN_RETRY_COUNT,
SQLSRV_CONN_OPTION_CONN_RETRY_INTERVAL,

View file

@ -3,7 +3,7 @@
//
// Contents: Core routines that use statement handles shared between sqlsrv and pdo_sqlsrv
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Implementation of PHP streams for reading SQL Server data
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -5,7 +5,7 @@
//
// Comments: Mostly error handling and some type handling
//
// Microsoft Drivers 4.1 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: Contains functions for handling Windows format strings
// and UTF-16 on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: Contains a portable abstraction for interlocked, atomic
// operations on int32_t and pointer types.
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: Contains a portable abstraction for interlocked, atomic
// operations on int32_t and pointer types.
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: Contains a portable abstraction for interlocked, singly
// linked list.
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Contains portable classes for localization
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -5,7 +5,7 @@
// Must be included in one c/cpp file per binary
// A build error will occur if this inclusion policy is not followed
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
//---------------------------------------------------------------------------------------------------------------------------------
// File: msodbcsql.h
//
// Contents: Routines that use statement handles
// Contents: Routines that use statement handles. This is a subset of the header file msodbcsql.h in the ODBC Driver.
//
// Contents: This SDK is not supported under any Microsoft standard support
// program or service. The information is provided AS IS without
@ -20,7 +20,7 @@
// pecuniary loss) arising out of the use of or inability to use
// this SDK, even if Microsoft has been advised of the possibility
// of such damages.
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -36,7 +36,7 @@
#if !defined(SQLODBC_VER)
#define SQLODBC_VER 1100
#define SQLODBC_VER 1300
#endif
#if SQLODBC_VER >= 1300
@ -46,7 +46,7 @@
#define SQLODBC_PRODUCT_NAME_SHORT_VER_ANSI "ODBC Driver 13 for SQL Server"
#define SQLODBC_PRODUCT_NAME_SHORT_ANSI "ODBC Driver for SQL Server"
#endif /* SQLODBC_VER >= 1300 */
#endif // SQLODBC_VER >= 1300
#define SQLODBC_PRODUCT_NAME_FULL_VER SQLODBC_PRODUCT_NAME_FULL_VER_ANSI
#define SQLODBC_PRODUCT_NAME_FULL SQLODBC_PRODUCT_NAME_FULL_ANSI
@ -55,147 +55,145 @@
#define SQLODBC_DRIVER_NAME SQLODBC_PRODUCT_NAME_SHORT_VER
/* max SQL Server identifier length */
// max SQL Server identifier length
#define SQL_MAX_SQLSERVERNAME 128
/*
* SQLSetConnectAttr driver specific defines.
* Microsoft has 1200 thru 1249 reserved for Microsoft ODBC Driver for SQL Server usage.
* Connection attributes
*/
// SQLSetConnectAttr driver specific defines.
// Microsoft has 1200 thru 1249 reserved for Microsoft ODBC Driver for SQL Server usage.
// Connection attributes
#define SQL_COPT_SS_BASE 1200
#define SQL_COPT_SS_INTEGRATED_SECURITY (SQL_COPT_SS_BASE+3) /* Force integrated security on login */
#define SQL_COPT_SS_TRANSLATE (SQL_COPT_SS_BASE+20) /* Perform code page translation */
#define SQL_COPT_SS_ENCRYPT (SQL_COPT_SS_BASE+23) /* Allow strong encryption for data */
#define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24) /* Multiple active result set per connection */
#define SQL_COPT_SS_TXN_ISOLATION (SQL_COPT_SS_BASE+27) /* Used to set/get any driver-specific or ODBC-defined TXN iso level */
#define SQL_COPT_SS_TRUST_SERVER_CERTIFICATE (SQL_COPT_SS_BASE+28) /* Trust server certificate */
/*
* SQLSetStmtAttr Microsoft ODBC Driver for SQL Server specific defines.
* Statement attributes
*/
#define SQL_COPT_SS_INTEGRATED_SECURITY (SQL_COPT_SS_BASE+3) // Force integrated security on login
#define SQL_COPT_SS_TRANSLATE (SQL_COPT_SS_BASE+20) // Perform code page translation
#define SQL_COPT_SS_ENCRYPT (SQL_COPT_SS_BASE+23) // Allow strong encryption for data
#define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24) // Multiple active result set per connection
#define SQL_COPT_SS_TXN_ISOLATION (SQL_COPT_SS_BASE+27) // Used to set/get any driver-specific or ODBC-defined TXN iso level
#define SQL_COPT_SS_TRUST_SERVER_CERTIFICATE (SQL_COPT_SS_BASE+28) // Trust server certificate
// SQLSetStmtAttr Microsoft ODBC Driver for SQL Server specific defines.
// Statement attributes
#define SQL_SOPT_SS_BASE 1225
#define SQL_SOPT_SS_TEXTPTR_LOGGING (SQL_SOPT_SS_BASE+0) /* Text pointer logging */
#define SQL_SOPT_SS_NOBROWSETABLE (SQL_SOPT_SS_BASE+3) /* Set NOBROWSETABLE option */
#define SQL_SOPT_SS_COLUMN_ENCRYPTION (SQL_SOPT_SS_BASE+13)/* Sets the column encryption mode */
/* Define old names */
#define SQL_SOPT_SS_TEXTPTR_LOGGING (SQL_SOPT_SS_BASE+0) // Text pointer logging
#define SQL_SOPT_SS_NOBROWSETABLE (SQL_SOPT_SS_BASE+3) // Set NOBROWSETABLE option
#define SQL_SOPT_SS_COLUMN_ENCRYPTION (SQL_SOPT_SS_BASE+13)// Sets the column encryption mode
// Define old names
#define SQL_TEXTPTR_LOGGING SQL_SOPT_SS_TEXTPTR_LOGGING
#define SQL_COPT_SS_BASE_EX 1240
#define SQL_COPT_SS_WARN_ON_CP_ERROR (SQL_COPT_SS_BASE_EX+3) /* Issues warning when data from the server had a loss during code page conversion. */
#define SQL_COPT_SS_CONNECTION_DEAD (SQL_COPT_SS_BASE_EX+4) /* dbdead SQLGetConnectOption only. It will try to ping the server. Expensive connection check */
#define SQL_COPT_SS_APPLICATION_INTENT (SQL_COPT_SS_BASE_EX+7) /* Application Intent */
#define SQL_COPT_SS_MULTISUBNET_FAILOVER (SQL_COPT_SS_BASE_EX+8) /* Multi-subnet Failover */
#define SQL_COPT_SS_TNIR (SQL_COPT_SS_BASE_EX+9) /* Transparent Network IP Resolution */
#define SQL_COPT_SS_COLUMN_ENCRYPTION (SQL_COPT_SS_BASE_EX+10) /* Always Encrypted Enabled or Disabled */
#define SQL_COPT_SS_AEKEYSTOREPROVIDER (SQL_COPT_SS_BASE_EX+11) /* Load a keystore provider or read the list of loaded keystore providers */
#define SQL_COPT_SS_AEKEYSTOREDATA (SQL_COPT_SS_BASE_EX+12) /* Communicate with a loaded keystore provider */
#define SQL_COPT_SS_AETRUSTEDCMKPATHS (SQL_COPT_SS_BASE_EX+13) /* List of trusted CMK paths */
#define SQL_COPT_SS_AECEKCACHETTL (SQL_COPT_SS_BASE_EX+14) /* Symmetric Key Cache TTL */
#define SQL_COPT_SS_AUTHENTICATION (SQL_COPT_SS_BASE_EX+15) /* The authentication method used for the connection */
#define SQL_COPT_SS_WARN_ON_CP_ERROR (SQL_COPT_SS_BASE_EX+3) // Issues warning when data from the server had a loss during code page conversion.
#define SQL_COPT_SS_CONNECTION_DEAD (SQL_COPT_SS_BASE_EX+4) // dbdead SQLGetConnectOption only. It will try to ping the server. Expensive connection check
#define SQL_COPT_SS_APPLICATION_INTENT (SQL_COPT_SS_BASE_EX+7) // Application Intent
#define SQL_COPT_SS_MULTISUBNET_FAILOVER (SQL_COPT_SS_BASE_EX+8) // Multi-subnet Failover
#define SQL_COPT_SS_TNIR (SQL_COPT_SS_BASE_EX+9) // Transparent Network IP Resolution
#define SQL_COPT_SS_COLUMN_ENCRYPTION (SQL_COPT_SS_BASE_EX+10)// Column Encryption Enabled or Disabled
#define SQL_COPT_SS_CEKEYSTOREPROVIDER (SQL_COPT_SS_BASE_EX+11)// Load a keystore provider or read the list of loaded keystore providers
#define SQL_COPT_SS_CEKEYSTOREDATA (SQL_COPT_SS_BASE_EX+12)// Communicate with loaded keystore providers
#define SQL_COPT_SS_TRUSTEDCMKPATHS (SQL_COPT_SS_BASE_EX+13)// List of trusted CMK paths
#define SQL_COPT_SS_CEKCACHETTL (SQL_COPT_SS_BASE_EX+14)// Symmetric Key Cache TTL
#define SQL_COPT_SS_AUTHENTICATION (SQL_COPT_SS_BASE_EX+15)// The authentication method used for the connection
/*
* SQLColAttributes driver specific defines.
* SQLSetDescField/SQLGetDescField driver specific defines.
* Microsoft has 1200 thru 1249 reserved for Microsoft ODBC Driver for SQL Server usage.
*/
// SQLColAttributes driver specific defines.
// SQLSetDescField/SQLGetDescField driver specific defines.
// Microsoft has 1200 thru 1249 reserved for Microsoft ODBC Driver for SQL Server usage.
#define SQL_CA_SS_BASE 1200
#define SQL_CA_SS_COLUMN_SSTYPE (SQL_CA_SS_BASE+0) /* dbcoltype/dbalttype */
#define SQL_CA_SS_COLUMN_UTYPE (SQL_CA_SS_BASE+1) /* dbcolutype/dbaltutype */
#define SQL_CA_SS_NUM_ORDERS (SQL_CA_SS_BASE+2) /* dbnumorders */
#define SQL_CA_SS_COLUMN_ORDER (SQL_CA_SS_BASE+3) /* dbordercol */
#define SQL_CA_SS_COLUMN_VARYLEN (SQL_CA_SS_BASE+4) /* dbvarylen */
#define SQL_CA_SS_NUM_COMPUTES (SQL_CA_SS_BASE+5) /* dbnumcompute */
#define SQL_CA_SS_COMPUTE_ID (SQL_CA_SS_BASE+6) /* dbnextrow status return */
#define SQL_CA_SS_COMPUTE_BYLIST (SQL_CA_SS_BASE+7) /* dbbylist */
#define SQL_CA_SS_COLUMN_ID (SQL_CA_SS_BASE+8) /* dbaltcolid */
#define SQL_CA_SS_COLUMN_OP (SQL_CA_SS_BASE+9) /* dbaltop */
#define SQL_CA_SS_COLUMN_SIZE (SQL_CA_SS_BASE+10) /* dbcollen */
#define SQL_CA_SS_COLUMN_HIDDEN (SQL_CA_SS_BASE+11) /* Column is hidden (FOR BROWSE) */
#define SQL_CA_SS_COLUMN_KEY (SQL_CA_SS_BASE+12) /* Column is key column (FOR BROWSE) */
#define SQL_CA_SS_COLUMN_COLLATION (SQL_CA_SS_BASE+14) /* Column collation (only for chars) */
#define SQL_CA_SS_COLUMN_SSTYPE (SQL_CA_SS_BASE+0) // dbcoltype/dbalttype
#define SQL_CA_SS_COLUMN_UTYPE (SQL_CA_SS_BASE+1) // dbcolutype/dbaltutype
#define SQL_CA_SS_NUM_ORDERS (SQL_CA_SS_BASE+2) // dbnumorders
#define SQL_CA_SS_COLUMN_ORDER (SQL_CA_SS_BASE+3) // dbordercol
#define SQL_CA_SS_COLUMN_VARYLEN (SQL_CA_SS_BASE+4) // dbvarylen
#define SQL_CA_SS_NUM_COMPUTES (SQL_CA_SS_BASE+5) // dbnumcompute
#define SQL_CA_SS_COMPUTE_ID (SQL_CA_SS_BASE+6) // dbnextrow status return
#define SQL_CA_SS_COMPUTE_BYLIST (SQL_CA_SS_BASE+7) // dbbylist
#define SQL_CA_SS_COLUMN_ID (SQL_CA_SS_BASE+8) // dbaltcolid
#define SQL_CA_SS_COLUMN_OP (SQL_CA_SS_BASE+9) // dbaltop
#define SQL_CA_SS_COLUMN_SIZE (SQL_CA_SS_BASE+10) // dbcollen
#define SQL_CA_SS_COLUMN_HIDDEN (SQL_CA_SS_BASE+11) // Column is hidden (FOR BROWSE)
#define SQL_CA_SS_COLUMN_KEY (SQL_CA_SS_BASE+12) // Column is key column (FOR BROWSE)
#define SQL_CA_SS_COLUMN_COLLATION (SQL_CA_SS_BASE+14) // Column collation (only for chars)
#define SQL_CA_SS_VARIANT_TYPE (SQL_CA_SS_BASE+15)
#define SQL_CA_SS_VARIANT_SQL_TYPE (SQL_CA_SS_BASE+16)
#define SQL_CA_SS_VARIANT_SERVER_TYPE (SQL_CA_SS_BASE+17)
/* XML, CLR UDT, and table valued parameter related metadata */
#define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18) /* UDT catalog name */
#define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19) /* UDT schema name */
#define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20) /* UDT type name */
#define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22) /* Name of the catalog that contains XML Schema collection */
#define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23) /* Name of the schema that contains XML Schema collection */
#define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24) /* Name of the XML Schema collection */
#define SQL_CA_SS_CATALOG_NAME (SQL_CA_SS_BASE+25) /* Catalog name */
#define SQL_CA_SS_SCHEMA_NAME (SQL_CA_SS_BASE+26) /* Schema name */
#define SQL_CA_SS_TYPE_NAME (SQL_CA_SS_BASE+27) /* Type name */
// XML, CLR UDT, and table valued parameter related metadata
#define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18) // UDT catalog name
#define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19) // UDT schema name
#define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20) // UDT type name
#define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22) // Name of the catalog that contains XML Schema collection
#define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23) // Name of the schema that contains XML Schema collection
#define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24) // Name of the XML Schema collection
#define SQL_CA_SS_CATALOG_NAME (SQL_CA_SS_BASE+25) // Catalog name
#define SQL_CA_SS_SCHEMA_NAME (SQL_CA_SS_BASE+26) // Schema name
#define SQL_CA_SS_TYPE_NAME (SQL_CA_SS_BASE+27) // Type name
/* table valued parameter related metadata */
#define SQL_CA_SS_COLUMN_COMPUTED (SQL_CA_SS_BASE+29) /* column is computed */
#define SQL_CA_SS_COLUMN_IN_UNIQUE_KEY (SQL_CA_SS_BASE+30) /* column is part of a unique key */
#define SQL_CA_SS_COLUMN_SORT_ORDER (SQL_CA_SS_BASE+31) /* column sort order */
#define SQL_CA_SS_COLUMN_SORT_ORDINAL (SQL_CA_SS_BASE+32) /* column sort ordinal */
#define SQL_CA_SS_COLUMN_HAS_DEFAULT_VALUE (SQL_CA_SS_BASE+33) /* column has default value for all rows of the table valued parameter */
// table valued parameter related metadata
#define SQL_CA_SS_COLUMN_COMPUTED (SQL_CA_SS_BASE+29) // column is computed
#define SQL_CA_SS_COLUMN_IN_UNIQUE_KEY (SQL_CA_SS_BASE+30) // column is part of a unique key
#define SQL_CA_SS_COLUMN_SORT_ORDER (SQL_CA_SS_BASE+31) // column sort order
#define SQL_CA_SS_COLUMN_SORT_ORDINAL (SQL_CA_SS_BASE+32) // column sort ordinal
#define SQL_CA_SS_COLUMN_HAS_DEFAULT_VALUE (SQL_CA_SS_BASE+33) // column has default value for all rows of the table valued parameter
/* sparse column related metadata */
#define SQL_CA_SS_IS_COLUMN_SET (SQL_CA_SS_BASE+34) /* column is a column-set column for sparse columns */
// sparse column related metadata
#define SQL_CA_SS_IS_COLUMN_SET (SQL_CA_SS_BASE+34) // column is a column-set column for sparse columns
/* Legacy datetime related metadata */
#define SQL_CA_SS_SERVER_TYPE (SQL_CA_SS_BASE+35) /* column type to send on the wire for datetime types */
// Legacy datetime related metadata
#define SQL_CA_SS_SERVER_TYPE (SQL_CA_SS_BASE+35) // column type to send on the wire for datetime types
/* force column encryption */
#define SQL_CA_SS_FORCE_ENCRYPT (SQL_CA_SS_BASE+36) /* indicate mandatory encryption for this parameter */
// force column encryption
#define SQL_CA_SS_FORCE_ENCRYPT (SQL_CA_SS_BASE+36) // indicate mandatory encryption for this parameter
/* Defines for use with SQL_COPT_SS_INTEGRATED_SECURITY - Pre-Connect Option only */
#define SQL_IS_OFF 0L /* Integrated security isn't used */
#define SQL_IS_ON 1L /* Integrated security is used */
#define SQL_CA_SS_MAX_USED (SQL_CA_SS_BASE+37)
// Defines for use with SQL_COPT_SS_INTEGRATED_SECURITY - Pre-Connect Option only
#define SQL_IS_OFF 0L // Integrated security isn't used
#define SQL_IS_ON 1L // Integrated security is used
#define SQL_IS_DEFAULT SQL_IS_OFF
/* Defines for use with SQL_COPT_SS_TRANSLATE */
#define SQL_XL_OFF 0L /* Code page translation is not performed */
#define SQL_XL_ON 1L /* Code page translation is performed */
// Defines for use with SQL_COPT_SS_TRANSLATE
#define SQL_XL_OFF 0L // Code page translation is not performed
#define SQL_XL_ON 1L // Code page translation is performed
#define SQL_XL_DEFAULT SQL_XL_ON
/* Defines for use with SQL_SOPT_SS_TEXTPTR_LOGGING */
#define SQL_TL_OFF 0L /* No logging on text pointer ops */
#define SQL_TL_ON 1L /* Logging occurs on text pointer ops */
// Defines for use with SQL_SOPT_SS_TEXTPTR_LOGGING
#define SQL_TL_OFF 0L // No logging on text pointer ops
#define SQL_TL_ON 1L // Logging occurs on text pointer ops
#define SQL_TL_DEFAULT SQL_TL_ON
/* Defines for use with SQL_SOPT_SS_NOBROWSETABLE */
#define SQL_NB_OFF 0L /* NO_BROWSETABLE is off */
#define SQL_NB_ON 1L /* NO_BROWSETABLE is on */
// Defines for use with SQL_SOPT_SS_NOBROWSETABLE
#define SQL_NB_OFF 0L // NO_BROWSETABLE is off
#define SQL_NB_ON 1L // NO_BROWSETABLE is on
#define SQL_NB_DEFAULT SQL_NB_OFF
/* Defines for use with SQL_SOPT_SS_COLUMN_ENCRYPTION */
#define SQL_CE_DISABLED 0L /* Disabled */
#define SQL_CE_RESULTSETONLY 1L /* Decryption Only (resultsets and return values) */
#define SQL_CE_ENABLED 3L /* Enabled (both encryption and decryption) */
/* SQL_COPT_SS_ENCRYPT */
// Defines for use with SQL_SOPT_SS_COLUMN_ENCRYPTION
#define SQL_CE_DISABLED 0L // Disabled
#define SQL_CE_RESULTSETONLY 1L // Decryption Only (resultsets and return values)
#define SQL_CE_ENABLED 3L // Enabled (both encryption and decryption)
// Defines for use with SQL_COPT_SS_COLUMN_ENCRYPTION
#define SQL_COLUMN_ENCRYPTION_DISABLE 0L
#define SQL_COLUMN_ENCRYPTION_ENABLE 1L
#define SQL_COLUMN_ENCRYPTION_DEFAULT SQL_COLUMN_ENCRYPTION_DISABLE
// Defines for use with SQL_COPT_SS_CEKCACHETTL
#define SQL_CEKCACHETTL_DEFAULT 7200L // TTL value in seconds (2 hours)
// SQL_COPT_SS_ENCRYPT
#define SQL_EN_OFF 0L
#define SQL_EN_ON 1L
/* SQL_COPT_SS_TRUST_SERVER_CERTIFICATE */
// SQL_COPT_SS_TRUST_SERVER_CERTIFICATE
#define SQL_TRUST_SERVER_CERTIFICATE_NO 0L
#define SQL_TRUST_SERVER_CERTIFICATE_YES 1L
/* SQL_COPT_SS_WARN_ON_CP_ERROR */
// SQL_COPT_SS_WARN_ON_CP_ERROR
#define SQL_WARN_NO 0L
#define SQL_WARN_YES 1L
/* SQL_COPT_SS_MARS_ENABLED */
// SQL_COPT_SS_MARS_ENABLED
#define SQL_MARS_ENABLED_NO 0L
#define SQL_MARS_ENABLED_YES 1L
/* SQL_TXN_ISOLATION_OPTION bitmasks */
// SQL_TXN_ISOLATION_OPTION bitmasks
#define SQL_TXN_SS_SNAPSHOT 0x00000020L
/* SQL_COPT_SS_COLUMN_ENCRYPTION */
#define SQL_COLUMN_ENCRYPTION_DISABLE 0L
#define SQL_COLUMN_ENCRYPTION_ENABLE 1L
#define SQL_COLUMN_ENCRYPTION_DEFAULT SQL_COLUMN_ENCRYPTION_DISABLE
// Defines for use with SQL_COPT_SS_AECEKCACHETTL
#define SQL_AECEKCACHETTL_DEFAULT 7200L // TTL value in seconds (2 hours)
/* The following are defines for SQL_CA_SS_COLUMN_SORT_ORDER */
// The following are defines for SQL_CA_SS_COLUMN_SORT_ORDER
#define SQL_SS_ORDER_UNSPECIFIED 0L
#define SQL_SS_DESCENDING_ORDER 1L
#define SQL_SS_ASCENDING_ORDER 2L
#define SQL_SS_ORDER_DEFAULT SQL_SS_ORDER_UNSPECIFIED
/*
* Driver specific SQL data type defines.
* Microsoft has -150 thru -199 reserved for Microsoft ODBC Driver for SQL Server usage.
*/
// Driver specific SQL data type defines.
// Microsoft has -150 thru -199 reserved for Microsoft ODBC Driver for SQL Server usage.
#define SQL_SS_VARIANT (-150)
#define SQL_SS_UDT (-151)
#define SQL_SS_XML (-152)
@ -203,24 +201,22 @@
#define SQL_SS_TIME2 (-154)
#define SQL_SS_TIMESTAMPOFFSET (-155)
/* Local types to be used with SQL_CA_SS_SERVER_TYPE */
// Local types to be used with SQL_CA_SS_SERVER_TYPE
#define SQL_SS_TYPE_DEFAULT 0L
#define SQL_SS_TYPE_SMALLDATETIME 1L
#define SQL_SS_TYPE_DATETIME 2L
/* Extended C Types range 4000 and above. Range of -100 thru 200 is reserved by Driver Manager. */
// Extended C Types range 4000 and above. Range of -100 thru 200 is reserved by Driver Manager.
#define SQL_C_TYPES_EXTENDED 0x04000L
/*
* SQL_SS_LENGTH_UNLIMITED is used to describe the max length of
* VARCHAR(max), VARBINARY(max), NVARCHAR(max), and XML columns
*/
// SQL_SS_LENGTH_UNLIMITED is used to describe the max length of
// VARCHAR(max), VARBINARY(max), NVARCHAR(max), and XML columns
#define SQL_SS_LENGTH_UNLIMITED 0
/*
* User Data Type definitions.
* Returned by SQLColAttributes/SQL_CA_SS_COLUMN_UTYPE.
*/
// User Data Type definitions.
// Returned by SQLColAttributes/SQL_CA_SS_COLUMN_UTYPE.
#define SQLudtBINARY 3
#define SQLudtBIT 16
#define SQLudtBITN 0
@ -250,35 +246,35 @@
#define SQLudtVARBINARY 4
#define SQLudtVARCHAR 2
#define MIN_USER_DATATYPE 256
/*
* Aggregate operator types.
* Returned by SQLColAttributes/SQL_CA_SS_COLUMN_OP.
*/
#define SQLAOPSTDEV 0x30 /* Standard deviation */
#define SQLAOPSTDEVP 0x31 /* Standard deviation population */
#define SQLAOPVAR 0x32 /* Variance */
#define SQLAOPVARP 0x33 /* Variance population */
#define SQLAOPCNT 0x4b /* Count */
#define SQLAOPSUM 0x4d /* Sum */
#define SQLAOPAVG 0x4f /* Average */
#define SQLAOPMIN 0x51 /* Min */
#define SQLAOPMAX 0x52 /* Max */
#define SQLAOPANY 0x53 /* Any */
#define SQLAOPNOOP 0x56 /* None */
/*
* SQLGetDiagField driver specific defines.
* Microsoft has -1150 thru -1199 reserved for Microsoft ODBC Driver for SQL Server usage.
*/
// Aggregate operator types.
// Returned by SQLColAttributes/SQL_CA_SS_COLUMN_OP.
#define SQLAOPSTDEV 0x30 // Standard deviation
#define SQLAOPSTDEVP 0x31 // Standard deviation population
#define SQLAOPVAR 0x32 // Variance
#define SQLAOPVARP 0x33 // Variance population
#define SQLAOPCNT 0x4b // Count
#define SQLAOPSUM 0x4d // Sum
#define SQLAOPAVG 0x4f // Average
#define SQLAOPMIN 0x51 // Min
#define SQLAOPMAX 0x52 // Max
#define SQLAOPANY 0x53 // Any
#define SQLAOPNOOP 0x56 // None
// SQLGetDiagField driver specific defines.
// Microsoft has -1150 thru -1199 reserved for Microsoft ODBC Driver for SQL Server usage.
#define SQL_DIAG_SS_BASE (-1150)
#define SQL_DIAG_SS_MSGSTATE (SQL_DIAG_SS_BASE)
#define SQL_DIAG_SS_SEVERITY (SQL_DIAG_SS_BASE-1)
#define SQL_DIAG_SS_SRVNAME (SQL_DIAG_SS_BASE-2)
#define SQL_DIAG_SS_PROCNAME (SQL_DIAG_SS_BASE-3)
#define SQL_DIAG_SS_LINE (SQL_DIAG_SS_BASE-4)
/*
* SQLGetDiagField/SQL_DIAG_DYNAMIC_FUNCTION_CODE driver specific defines.
* Microsoft has -200 thru -299 reserved for Microsoft ODBC Driver for SQL Server usage.
*/
// SQLGetDiagField/SQL_DIAG_DYNAMIC_FUNCTION_CODE driver specific defines.
// Microsoft has -200 thru -299 reserved for Microsoft ODBC Driver for SQL Server usage.
#define SQL_DIAG_DFC_SS_BASE (-200)
#define SQL_DIAG_DFC_SS_ALTER_DATABASE (SQL_DIAG_DFC_SS_BASE-0)
#define SQL_DIAG_DFC_SS_CHECKPOINT (SQL_DIAG_DFC_SS_BASE-1)
@ -343,7 +339,7 @@
#define SQL_DIAG_DFC_SS_SET_XCTLVL (SQL_DIAG_DFC_SS_BASE-55)
#define SQL_DIAG_DFC_SS_MERGE (SQL_DIAG_DFC_SS_BASE-56)
/* Severity codes for SQL_DIAG_SS_SEVERITY */
// Severity codes for SQL_DIAG_SS_SEVERITY
#define EX_ANY 0
#define EX_INFO 10
#define EX_MAXISEVERITY EX_INFO
@ -365,64 +361,45 @@
#define EX_HARDWARE 24
#define EX_CONTROL 25
/* Keystore Provider interface definition */
// Data is defined to be past the end of the structure header.
// This is accepted by MSVC, GCC, and C99 standard but former emits
// unnecessary warning, hence it has to be disabled.
typedef void errFunc(void *ctx, const wchar_t *msg, ...);
#define IDS_MSG(x) ((const wchar_t*)(x))
typedef struct AEKeystoreProvider
{
wchar_t *Name;
int (*Init)(void *ctx, errFunc *onError);
int (*Read)(void *ctx, errFunc *onError, void *data, unsigned int *len);
int (*Write)(void *ctx, errFunc *onError, void *data, unsigned int len);
int (*DecryptCEK)(
void *ctx,
errFunc *onError,
const wchar_t *keyPath,
const wchar_t *alg,
unsigned char *ecek,
unsigned short ecek_len,
unsigned char **cek_out,
unsigned short *cek_len);
void (*Free)();
} AEKEYSTOREPROVIDER;
/* Data is defined to be past the end of the structure header.
This is accepted by MSVC, GCC, and C99 standard but former emits
unnecessary warning, hence it has to be disabled.
*/
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4200)
#endif
typedef struct AEKeystoreData
// Communication between the driver and application via the CEKeystoreData structure
typedef struct CEKeystoreData
{
wchar_t *Name;
wchar_t *name;
unsigned int dataSize;
char Data[];
} AEKEYSTOREPROVIDERDATA;
char data[];
} CEKEYSTOREDATA;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
/* The following constants are for the Azure Key Vault configuration interface */
#define AKV_CONFIG_FLAGS 0
#define AKVCFG_USECLIENTID 0x00000001
#define AKVCFG_AUTORENEW 0x00000002
#define AKV_CONFIG_CLIENTID 1
#define AKV_CONFIG_CLIENTKEY 2
#define AKV_CONFIG_ACCESSTOKEN 3
#define AKV_CONFIG_TOKENEXPIRY 4
// The following constants are for the Azure Key Vault configuration interface
#define AKV_CONFIG_FLAGS 0
#define AKVCFG_AUTHMODE 0x0000000F
#define AKVCFG_AUTHMODE_ACCESSTOKEN 0
#define AKVCFG_AUTHMODE_CLIENTKEY 1
#define AKVCFG_AUTHMODE_PASSWORD 2
#define AKVCFG_AUTHMODE_INTEGRATED 3
#define AKVCFG_AUTHMODE_CERTIFICATE 4
#define AKVCFG_NOAUTORENEW 0x00000010
#define AKV_CONFIG_PRINCIPALID 1
#define AKV_CONFIG_AUTHSECRET 2
#define AKV_CONFIG_ACCESSTOKEN 3
#define AKV_CONFIG_TOKENEXPIRY 4
#define AKV_CONFIG_MAXRETRIES 5
#define AKV_CONFIG_RETRYTIMEOUT 6
#define AKV_CONFIG_RETRYWAIT 7
#endif /* __msodbcsql_h__ */
#define AKV_CONFIG_RESET 255
#endif // __msodbcsql_h__

View file

@ -3,7 +3,7 @@
//
// Contents: Contains the minimal definitions to build on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -1,7 +1,7 @@
//---------------------------------------------------------------------------------------------------------------------------------
// File: typedefs_for_linux.h
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// File: version.h
// Contents: Version number constants
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -22,14 +22,21 @@
#define STRINGIFY(a) TOSTRING(a)
#define TOSTRING(a) #a
// Increase Major number with backward incompatible breaking changes.
// Increase Minor with backward compatible new functionalities and API changes.
// Increase Patch for backward compatible fixes.
#define SQLVERSION_MAJOR 4
#define SQLVERSION_MINOR 2
#define SQLVERSION_MINOR 3
#define SQLVERSION_PATCH 0
#define SQLVERSION_BUILD 0
// Semantic versioning pre-release, for stable releases should be empty
#define SEMVER_PRERELEASE "preview"
// Semantic versioning build metadata
// Semantic versioning pre-release
// for stable releases should be empty
// "rc" for release candidates
// "preview" for ETP
#define SEMVER_PRERELEASE "RC1"
// Semantic versioning build metadata, build meta data is not counted in precedence order.
#define SEMVER_BUILDMETA
#if SQLVERSION_BUILD > 0
@ -37,7 +44,7 @@
#define SEMVER_BUILDMETA "+" STRINGIFY( SQLVERSION_BUILD )
#endif
// Main version
// Main version, dot separated 3 digits, Major.Minor.Patch
#define VER_APIVERSION_STR STRINGIFY( SQLVERSION_MAJOR ) "." STRINGIFY( SQLVERSION_MINOR ) "." STRINGIFY( SQLVERSION_PATCH )
// Remove "-" if SEMVER_PRERELEASE is empty (for stable releases)

View file

@ -3,7 +3,7 @@
//
// Contents: include for definition of Windows types for non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -4,7 +4,7 @@
// Contents: This module defines helper functions to prevent
// integer overflow bugs.
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Contains the minimal definitions to build on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Contains the minimal definitions to build on non-Windows platforms
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -40,3 +40,8 @@ if test "$PHP_SQLSRV" != "no"; then
PHP_NEW_EXTENSION(sqlsrv, $sqlsrv_src_class $shared_src_class, $ext_shared,,-std=c++11)
PHP_ADD_BUILD_DIR([$ext_builddir/shared], 1)
fi
#if (defined __APPLE__ && defined __MACH__) \
MACOSX_DEPLOYMENT_TARGET=`sw_vers -productVersion` \
#endif

View file

@ -3,7 +3,7 @@
//
// Contents: JScript build configuration used by buildconf.bat
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Routines that use connection handles
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -205,6 +205,7 @@ const char TraceFile[] = "TraceFile";
const char TraceOn[] = "TraceOn";
const char TrustServerCertificate[] = "TrustServerCertificate";
const char TransactionIsolation[] = "TransactionIsolation";
const char TransparentNetworkIPResolution[] = "TransparentNetworkIPResolution";
const char UID[] = "UID";
const char WSID[] = "WSID";
@ -420,6 +421,15 @@ const connection_option SS_CONN_OPTS[] = {
CONN_ATTR_BOOL,
bool_conn_str_func::func
},
{
SSConnOptionNames::TransparentNetworkIPResolution,
sizeof(SSConnOptionNames::TransparentNetworkIPResolution),
SQLSRV_CONN_OPTION_TRANSPARANT_NETWORK_IP_RESOLUTION,
ODBCConnOptions::TransparentNetworkIPResolution,
sizeof(ODBCConnOptions::TransparentNetworkIPResolution),
CONN_ATTR_STRING,
conn_str_append_func::func
},
{
SSConnOptionNames::WSID,
sizeof( SSConnOptionNames::WSID ),
@ -658,7 +668,11 @@ PHP_FUNCTION( sqlsrv_close )
if( zend_list_close( Z_RES_P( conn_r ) ) == FAILURE ) {
LOG( SEV_ERROR, "Failed to remove connection resource %1!d!", Z_RES_HANDLE_P( conn_r ));
}
// when conn_r is first parsed in zend_parse_parameters, conn_r becomes a zval that points to a zend_resource with a refcount of 2
// need to DELREF here so the refcount becomes 1 and conn_r can be appropriate destroyed by the garbage collector when it goes out of scope
// zend_list_close only destroy the resource pointed to by Z_RES_P( conn_r ), not the zend_resource itself
Z_TRY_DELREF_P(conn_r);
ZVAL_NULL( conn_r );
RETURN_TRUE;

View file

@ -2,7 +2,7 @@
// File: init.cpp
// Contents: initialization routines for the extension
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -8,7 +8,7 @@
//
// Comments: Also contains "internal" declarations shared across source files.
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -3,7 +3,7 @@
//
// Contents: Routines that use statement handles
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -1376,6 +1376,10 @@ PHP_FUNCTION( sqlsrv_free_stmt )
LOG( SEV_ERROR, "Failed to remove stmt resource %1!d!", Z_RES_P( stmt_r )->handle);
}
// when stmt_r is first parsed in zend_parse_parameters, stmt_r becomes a zval that points to a zend_resource with a refcount of 2
// need to DELREF here so the refcount becomes 1 and stmt_r can be appropriate destroyed by the garbage collector when it goes out of scope
// zend_list_close only destroy the resource pointed to by Z_RES_P( stmt_r ), not the zend_resource itself
Z_TRY_DELREF_P(stmt_r);
ZVAL_NULL( stmt_r );
RETURN_TRUE;

View file

@ -3,7 +3,7 @@
//
// Contents: Version resource
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License

View file

@ -5,7 +5,7 @@
//
// Comments: Mostly error handling and some type handling
//
// Microsoft Drivers 4.2 for PHP for SQL Server
// Microsoft Drivers 4.3 for PHP for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
@ -684,8 +684,6 @@ PHP_FUNCTION( sqlsrv_get_config )
namespace {
// Workaround for name collision problem between the SQLSRV and PDO_SQLSRV drivers on Mac
// Place get_error_message into the anonymous namespace in util.cpp
sqlsrv_error_const* get_error_message( unsigned int sqlsrv_error_code ) {
sqlsrv_error_const *error_message = NULL;

View file

@ -0,0 +1,60 @@
<?php
function RestartConn($server)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Stop()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
// Wait until the service is fully stopped
while (substr_count($servstring, "Stopped") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
}
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Start()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
// Wait until the service is fully started
while (substr_count($servstring, "Running") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
}
}
function StopConn($server)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Stop()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
// Wait until the service is fully stopped
while (substr_count($servstring, "Stopped") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
}
}
function StartConn($server)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
if (substr_count($servstring, "Running") != 1)
{
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Start()";
exec( $restart_string );
}
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
// Wait until the service is fully started
while (substr_count($servstring, "Running") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
}
}
?>

View file

@ -0,0 +1,82 @@
<?php
require_once("ConInfo.inc");
// Using the tempdb database for two tables specifically constructed
// for the connection resiliency tests
$dbName = "tempdb";
$tableName1 = "test_connres1";
$tableName2 = "test_connres2";
// Generate tables for use with the connection resiliency tests.
// Using generated tables will eventually allow us to put the
// connection resiliency tests on Github, since the integrated testing
// from AppVeyor does not have AdventureWorks.
function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 )
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
if ( $conn === false )
{
die ( print_r( sqlsrv_errors() ) );
}
// Create table
$sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )";
$stmt = $conn->query( $sql );
// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
for( $t = 100; $t < 116; $t++ )
{
$stmt = $conn->prepare( $sql );
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt->execute( $params );
}
// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$stmt = $conn->query( $sql );
// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
for( $t = 200; $t < 209; $t++ )
{
$stmt = $conn->prepare( $sql );
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt->execute( $params );
}
$conn = null;
}
// Break connection by getting the session ID and killing it.
// Note that breaking a connection and testing reconnection requires a
// TCP/IP protocol connection (as opposed to a Shared Memory protocol).
function BreakConnection( $conn, $conn_break )
{
$stmt1 = $conn->query( "SELECT @@SPID" );
$obj = $stmt1->fetch( PDO::FETCH_NUM );
$spid = $obj[0];
$stmt2 = $conn_break->query( "KILL ".$spid );
sleep(1);
}
// Remove any databases previously created by GenerateDatabase
function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
{
$conn = new PDO( "sqlsrv:server = $server ; ", $uid, $pwd );
$query="IF OBJECT_ID('tempdb.dbo.$tableName1', 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName1";
$stmt=$conn->query( $query );
$query="IF OBJECT_ID('tempdb.dbo.$tableName2', 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName2";
$stmt=$conn->query( $query );
}
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 );
?>

View file

@ -0,0 +1,8 @@
<?php
$server = 'TARGET_SERVER';
$databaseName = 'TARGET_DATABASE';
$uid = 'TARGET_USERNAME';
$pwd = 'TARGET_PASSWORD';
?>

View file

@ -0,0 +1,24 @@
--TEST--
a variable bound to a column in a result set
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "SELECT Title, FirstName, EmailPromotion FROM Person.Person where LastName = 'Estes'";
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('EmailPromotion', $emailpromo);
while ( $row = $stmt->fetch( PDO::FETCH_BOUND ) ){
echo "EmailPromotion: $emailpromo\n";
}
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
EmailPromotion: 2

View file

@ -0,0 +1,38 @@
--TEST--
after a variable is bound, changing the value changes the value passed in the query
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$contact = "Sales Agent";
$stmt = $conn->prepare("select * from Person.ContactType where name = ?");
$stmt->bindParam(1, $contact);
$contact = "Owner";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "Result: "."$row[Name]\n\n";
}
$stmt = null;
$contact = "Sales Agent";
$stmt = $conn->prepare("select * from Person.ContactType where name = :contact");
$stmt->bindParam(':contact', $contact);
$contact = "Owner";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "Result: "."$row[Name]\n\n";
}
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
Result: Owner
Result: Owner

View file

@ -0,0 +1,22 @@
--TEST--
accesses an output parameter
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$input1 = 'bb';
$stmt = $conn->prepare("select ? = count(* ) from Person.Person");
$stmt->bindParam( 1, $input1, PDO::PARAM_STR, 10);
$stmt->execute();
echo "Result: ".$input1;
//free the statement and connection
$conn = null;
$stmt = null;
?>
--EXPECT--
Result: 19972

View file

@ -0,0 +1,23 @@
--TEST--
uses an input/output parameter
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$dbh = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString");
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?");
$string = "123456789";
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
$stmt->execute();
print "Result: ".$string; // Expect 987654321
//free the statement and connection
$stmt = null;
$dbh = null;
?>
--EXPECT--
Result: 987654321

View file

@ -0,0 +1,38 @@
--TEST--
after a value $contact is bound, changing the value does not change the value passed in the query
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$contact = "Sales Agent";
$stmt = $conn->prepare("select * from Person.ContactType where name = ?");
$stmt->bindValue(1, $contact);
$contact = "Owner";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "Name: $row[Name]\n\n";
}
$stmt = null;
$contact = "Sales Agent";
$stmt = $conn->prepare("select * from Person.ContactType where name = :contact");
$stmt->bindValue(':contact', $contact);
$contact = "Owner";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "Name: $row[Name]\n\n";
}
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Name: Sales Agent
Name: Sales Agent

View file

@ -0,0 +1,50 @@
--TEST--
closes the cursor
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd", array('MultipleActiveResultSets' => false ) );
$stmt = $conn->prepare('SELECT * FROM Person.ContactType');
$stmt2 = $conn->prepare('SELECT * FROM HumanResources.Department');
$stmt->execute();
$result = $stmt->fetch();
print_r($result);
$stmt->closeCursor();
$stmt2->execute();
$result = $stmt2->fetch();
print_r($result);
//free the statements and connection
$stmt=null;
$stmt2=null;
$conn=null;
?>
--EXPECT--
Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
Array
(
[DepartmentID] => 1
[0] => 1
[Name] => Engineering
[1] => Engineering
[GroupName] => Research and Development
[2] => Research and Development
[ModifiedDate] => 2008-04-30 00:00:00.000
[3] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,34 @@
--TEST--
returns the number of columns in a result set for 3 queries
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "select * from Person.ContactType";
$stmt = $conn->prepare( $query );
print $stmt->columnCount(); // 0
echo " columns in the result set\n";
echo "\n";
$stmt->execute();
print $stmt->columnCount();
echo " columns in the result set\n";
echo "\n";
$stmt = $conn->query("select * from HumanResources.Department");
print $stmt->columnCount();
echo " columns in the result set\n";
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
0 columns in the result set
3 columns in the result set
4 columns in the result set

View file

@ -0,0 +1,42 @@
--TEST--
displays a prepared statement
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$param = "Owner";
$stmt = $conn->prepare("select * from Person.ContactType where name = :param");
$stmt->execute(array($param));
$stmt->debugDumpParams();
echo "\n\n";
$stmt = $conn->prepare("select * from Person.ContactType where name = ?");
$stmt->execute(array($param));
$stmt->debugDumpParams();
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
SQL: [52] select * from Person.ContactType where name = :param
Params: 1
Key: Name: [6] :param
paramno=0
name=[6] ":param"
is_param=1
param_type=2
SQL: [47] select * from Person.ContactType where name = ?
Params: 1
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=2

View file

@ -0,0 +1,20 @@
--TEST--
shows the error code of a SQL query with a mispelled table
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->prepare('SELECT * FROM Person.Addressx');
$stmt->execute();
echo "Error Code: ";
print $stmt->errorCode();
// free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Error Code: 42S02

View file

@ -0,0 +1,24 @@
--TEST--
reports the error info of a SQL statement with a mispelled table name
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->prepare('SELECT * FROM Person.Addressx');
$stmt->execute();
print_r ($stmt->errorInfo());
// free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECTREGEX--
Array
\(
\[0\] => 42S02
\[1\] => 208
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Invalid object name 'Person.Addressx'.
\)

View file

@ -0,0 +1,54 @@
--TEST--
Executes a statement
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "select * from Person.ContactType";
$stmt = $conn->prepare( $query );
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "$row[Name]\n";
}
echo "\n";
$param = "Owner";
$query = "select * from Person.ContactType where name = ?";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "$row[Name]\n";
}
// free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
Export Administrator
International Marketing Manager
Marketing Assistant
Marketing Manager
Marketing Representative
Order Administrator
Owner
Owner/Marketing Assistant
Product Manager
Purchasing Agent
Purchasing Manager
Regional Account Representative
Sales Agent
Sales Associate
Sales Manager
Sales Representative
Owner

View file

@ -0,0 +1,152 @@
--TEST--
fetch with all fetch styles
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
print( "\n---------- PDO::FETCH_CLASS -------------\n" );
$stmt = $conn->query( "select * from HumanResources.Department order by GroupName" );
class cc {
function __construct( $arg ) {
echo "$arg";
}
function __toString() {
return $this->DepartmentID . "; " . $this->Name . "; " . $this->GroupName;
}
}
$stmt->setFetchMode(PDO::FETCH_CLASS, 'cc', array( "arg1 " ));
while ( $row = $stmt->fetch(PDO::FETCH_CLASS)) {
print($row . "\n");
}
print( "\n---------- PDO::FETCH_INTO -------------\n" );
$stmt = $conn->query( "select * from HumanResources.Department order by GroupName" );
$c_obj = new cc( '' );
$stmt->setFetchMode(PDO::FETCH_INTO, $c_obj);
while ( $row = $stmt->fetch(PDO::FETCH_INTO)) {
echo "$c_obj\n";
}
print( "\n---------- PDO::FETCH_ASSOC -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetch( PDO::FETCH_ASSOC );
print_r( $result );
print( "\n---------- PDO::FETCH_NUM -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetch( PDO::FETCH_NUM );
print_r ($result );
print( "\n---------- PDO::FETCH_BOTH -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetch( PDO::FETCH_BOTH );
print_r( $result );
print( "\n---------- PDO::FETCH_LAZY -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetch( PDO::FETCH_LAZY );
print_r( $result );
print( "\n---------- PDO::FETCH_OBJ -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetch( PDO::FETCH_OBJ );
print $result->Name;
print( "\n \n" );
print( "\n---------- PDO::FETCH_BOUND -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->bindColumn('Name', $name);
$result = $stmt->fetch( PDO::FETCH_BOUND );
print $name;
print( "\n \n" );
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
---------- PDO::FETCH_CLASS -------------
arg1 9; Human Resources; Executive General and Administration
arg1 10; Finance; Executive General and Administration
arg1 11; Information Services; Executive General and Administration
arg1 14; Facilities and Maintenance; Executive General and Administration
arg1 16; Executive; Executive General and Administration
arg1 15; Shipping and Receiving; Inventory Management
arg1 5; Purchasing; Inventory Management
arg1 7; Production; Manufacturing
arg1 8; Production Control; Manufacturing
arg1 12; Document Control; Quality Assurance
arg1 13; Quality Assurance; Quality Assurance
arg1 6; Research and Development; Research and Development
arg1 1; Engineering; Research and Development
arg1 2; Tool Design; Research and Development
arg1 3; Sales; Sales and Marketing
arg1 4; Marketing; Sales and Marketing
---------- PDO::FETCH_INTO -------------
9; Human Resources; Executive General and Administration
10; Finance; Executive General and Administration
11; Information Services; Executive General and Administration
14; Facilities and Maintenance; Executive General and Administration
16; Executive; Executive General and Administration
15; Shipping and Receiving; Inventory Management
5; Purchasing; Inventory Management
7; Production; Manufacturing
8; Production Control; Manufacturing
12; Document Control; Quality Assurance
13; Quality Assurance; Quality Assurance
6; Research and Development; Research and Development
1; Engineering; Research and Development
2; Tool Design; Research and Development
3; Sales; Sales and Marketing
4; Marketing; Sales and Marketing
---------- PDO::FETCH_ASSOC -------------
Array
(
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_NUM -------------
Array
(
[0] => 1
[1] => Accounting Manager
[2] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_BOTH -------------
Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_LAZY -------------
PDORow Object
(
[queryString] => select * from Person.ContactType where ContactTypeID < 5
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_OBJ -------------
Accounting Manager
---------- PDO::FETCH_BOUND -------------
Accounting Manager

View file

@ -0,0 +1,156 @@
--TEST--
fetches the rows in a result set in an array
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
print "-----------\n";
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetchAll(PDO::FETCH_BOTH);
print_r( $result );
print "\n-----------\n";
print "-----------\n";
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetchAll(PDO::FETCH_NUM);
print_r( $result );
print "\n-----------\n";
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetchAll(PDO::FETCH_COLUMN, 1);
print_r( $result );
print "\n-----------\n";
class cc {
function __construct( $arg ) {
echo "$arg\n";
}
function __toString() {
echo "To string\n";
}
};
$stmt = $conn->query( 'SELECT TOP(2) * FROM Person.ContactType' );
$all = $stmt->fetchAll( PDO::FETCH_CLASS, 'cc', array( 'Hi!' ));
var_dump( $all );
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
-----------
Array
(
[0] => Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
[1] => Array
(
[ContactTypeID] => 2
[0] => 2
[Name] => Assistant Sales Agent
[1] => Assistant Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
[2] => Array
(
[ContactTypeID] => 3
[0] => 3
[Name] => Assistant Sales Representative
[1] => Assistant Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
[3] => Array
(
[ContactTypeID] => 4
[0] => 4
[Name] => Coordinator Foreign Markets
[1] => Coordinator Foreign Markets
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
)
-----------
-----------
Array
(
[0] => Array
(
[0] => 1
[1] => Accounting Manager
[2] => 2008-04-30 00:00:00.000
)
[1] => Array
(
[0] => 2
[1] => Assistant Sales Agent
[2] => 2008-04-30 00:00:00.000
)
[2] => Array
(
[0] => 3
[1] => Assistant Sales Representative
[2] => 2008-04-30 00:00:00.000
)
[3] => Array
(
[0] => 4
[1] => Coordinator Foreign Markets
[2] => 2008-04-30 00:00:00.000
)
)
-----------
Array
(
[0] => Accounting Manager
[1] => Assistant Sales Agent
[2] => Assistant Sales Representative
[3] => Coordinator Foreign Markets
)
-----------
Hi!
Hi!
array(2) {
[0]=>
object(cc)#2 (3) {
["ContactTypeID"]=>
string(1) "1"
["Name"]=>
string(18) "Accounting Manager"
["ModifiedDate"]=>
string(23) "2008-04-30 00:00:00.000"
}
[1]=>
object(cc)#4 (3) {
["ContactTypeID"]=>
string(1) "2"
["Name"]=>
string(21) "Assistant Sales Agent"
["ModifiedDate"]=>
string(23) "2008-04-30 00:00:00.000"
}
}

View file

@ -0,0 +1,23 @@
--TEST--
fetches a column in a row
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
while ( $result = $stmt->fetchColumn(1)) {
print($result . "\n");
}
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets

View file

@ -0,0 +1,19 @@
--TEST--
fetches the next row as an object
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$result = $stmt->fetchObject();
print $result->Name;
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Accounting Manager

View file

@ -0,0 +1,36 @@
--TEST--
fetches the next row as an object of a user defined class
--SKIPIF--
--FILE--
<?php
//create class of contactType
//the names of the attributes in the class has to be the same as the column names in the database
class contactTypes{
public $ContactTypeID;
public $Name;
public $ModifiedDate;
// function that increments that contact id by 10
public function upperCaseName(){
return strtoupper($this->Name);
}
}// end of class
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID = 5 " );
$contactTypes = $stmt->fetchObject('contactTypes');
//print the class properties
print $contactTypes->ContactTypeID."\n";
print $contactTypes->upperCaseName()."\n";
print $contactTypes->ModifiedDate;
// close the database connection
$stmt=null;
$conn=null;
?>
--EXPECT--
5
EXPORT ADMINISTRATOR
2008-04-30 00:00:00.000

View file

@ -0,0 +1,43 @@
--TEST--
retrieves metadata for a column
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt = $conn->query("select * from Person.ContactType");
$metadata = $stmt->getColumnMeta(2);
var_dump($metadata);
print $metadata['sqlsrv:decl_type'] . "\n";
print $metadata['native_type'] . "\n";
print $metadata['name'];
// free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(8) "datetime"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(12) "ModifiedDate"
["len"]=>
int(23)
["precision"]=>
int(3)
}
datetime
string
ModifiedDate

View file

@ -0,0 +1,350 @@
--TEST--
moves the cursor to the next result set and fetches results
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query1 = "select AddressID from Person.Address where City = 'Bothell'";
$query2 = "select Name from Person.ContactType";
$stmt = $conn->query( $query1 . $query2);
$rowset1 = $stmt->fetchAll();
$stmt->nextRowset();
$rowset2 = $stmt->fetchAll();
var_dump( $rowset1 );
var_dump( $rowset2 );
// free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
array(26) {
[0]=>
array(2) {
["AddressID"]=>
string(1) "5"
[0]=>
string(1) "5"
}
[1]=>
array(2) {
["AddressID"]=>
string(2) "11"
[0]=>
string(2) "11"
}
[2]=>
array(2) {
["AddressID"]=>
string(1) "6"
[0]=>
string(1) "6"
}
[3]=>
array(2) {
["AddressID"]=>
string(2) "18"
[0]=>
string(2) "18"
}
[4]=>
array(2) {
["AddressID"]=>
string(2) "40"
[0]=>
string(2) "40"
}
[5]=>
array(2) {
["AddressID"]=>
string(1) "1"
[0]=>
string(1) "1"
}
[6]=>
array(2) {
["AddressID"]=>
string(2) "10"
[0]=>
string(2) "10"
}
[7]=>
array(2) {
["AddressID"]=>
string(3) "868"
[0]=>
string(3) "868"
}
[8]=>
array(2) {
["AddressID"]=>
string(2) "19"
[0]=>
string(2) "19"
}
[9]=>
array(2) {
["AddressID"]=>
string(2) "16"
[0]=>
string(2) "16"
}
[10]=>
array(2) {
["AddressID"]=>
string(2) "15"
[0]=>
string(2) "15"
}
[11]=>
array(2) {
["AddressID"]=>
string(2) "12"
[0]=>
string(2) "12"
}
[12]=>
array(2) {
["AddressID"]=>
string(5) "18249"
[0]=>
string(5) "18249"
}
[13]=>
array(2) {
["AddressID"]=>
string(1) "7"
[0]=>
string(1) "7"
}
[14]=>
array(2) {
["AddressID"]=>
string(2) "21"
[0]=>
string(2) "21"
}
[15]=>
array(2) {
["AddressID"]=>
string(1) "8"
[0]=>
string(1) "8"
}
[16]=>
array(2) {
["AddressID"]=>
string(2) "17"
[0]=>
string(2) "17"
}
[17]=>
array(2) {
["AddressID"]=>
string(2) "20"
[0]=>
string(2) "20"
}
[18]=>
array(2) {
["AddressID"]=>
string(5) "26486"
[0]=>
string(5) "26486"
}
[19]=>
array(2) {
["AddressID"]=>
string(1) "3"
[0]=>
string(1) "3"
}
[20]=>
array(2) {
["AddressID"]=>
string(2) "14"
[0]=>
string(2) "14"
}
[21]=>
array(2) {
["AddressID"]=>
string(1) "9"
[0]=>
string(1) "9"
}
[22]=>
array(2) {
["AddressID"]=>
string(2) "13"
[0]=>
string(2) "13"
}
[23]=>
array(2) {
["AddressID"]=>
string(1) "4"
[0]=>
string(1) "4"
}
[24]=>
array(2) {
["AddressID"]=>
string(1) "2"
[0]=>
string(1) "2"
}
[25]=>
array(2) {
["AddressID"]=>
string(3) "834"
[0]=>
string(3) "834"
}
}
array(20) {
[0]=>
array(2) {
["Name"]=>
string(18) "Accounting Manager"
[0]=>
string(18) "Accounting Manager"
}
[1]=>
array(2) {
["Name"]=>
string(21) "Assistant Sales Agent"
[0]=>
string(21) "Assistant Sales Agent"
}
[2]=>
array(2) {
["Name"]=>
string(30) "Assistant Sales Representative"
[0]=>
string(30) "Assistant Sales Representative"
}
[3]=>
array(2) {
["Name"]=>
string(27) "Coordinator Foreign Markets"
[0]=>
string(27) "Coordinator Foreign Markets"
}
[4]=>
array(2) {
["Name"]=>
string(20) "Export Administrator"
[0]=>
string(20) "Export Administrator"
}
[5]=>
array(2) {
["Name"]=>
string(31) "International Marketing Manager"
[0]=>
string(31) "International Marketing Manager"
}
[6]=>
array(2) {
["Name"]=>
string(19) "Marketing Assistant"
[0]=>
string(19) "Marketing Assistant"
}
[7]=>
array(2) {
["Name"]=>
string(17) "Marketing Manager"
[0]=>
string(17) "Marketing Manager"
}
[8]=>
array(2) {
["Name"]=>
string(24) "Marketing Representative"
[0]=>
string(24) "Marketing Representative"
}
[9]=>
array(2) {
["Name"]=>
string(19) "Order Administrator"
[0]=>
string(19) "Order Administrator"
}
[10]=>
array(2) {
["Name"]=>
string(5) "Owner"
[0]=>
string(5) "Owner"
}
[11]=>
array(2) {
["Name"]=>
string(25) "Owner/Marketing Assistant"
[0]=>
string(25) "Owner/Marketing Assistant"
}
[12]=>
array(2) {
["Name"]=>
string(15) "Product Manager"
[0]=>
string(15) "Product Manager"
}
[13]=>
array(2) {
["Name"]=>
string(16) "Purchasing Agent"
[0]=>
string(16) "Purchasing Agent"
}
[14]=>
array(2) {
["Name"]=>
string(18) "Purchasing Manager"
[0]=>
string(18) "Purchasing Manager"
}
[15]=>
array(2) {
["Name"]=>
string(31) "Regional Account Representative"
[0]=>
string(31) "Regional Account Representative"
}
[16]=>
array(2) {
["Name"]=>
string(11) "Sales Agent"
[0]=>
string(11) "Sales Agent"
}
[17]=>
array(2) {
["Name"]=>
string(15) "Sales Associate"
[0]=>
string(15) "Sales Associate"
}
[18]=>
array(2) {
["Name"]=>
string(13) "Sales Manager"
[0]=>
string(13) "Sales Manager"
}
[19]=>
array(2) {
["Name"]=>
string(20) "Sales Representative"
[0]=>
string(20) "Sales Representative"
}
}

View file

@ -0,0 +1,45 @@
--TEST--
returns the number of rows added to a table; returns the number of rows in a result set when you specify a scrollable cursor
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
$conn->exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
$col1 = 'a';
$col2 = 'b';
$query = "insert into Table1(col1, col2) values(?, ?)";
$stmt = $conn->prepare( $query );
$stmt->execute( array( $col1, $col2 ) );
print $stmt->rowCount();
print " rows affects.";
echo "\n\n";
//revert the insert
$conn->exec("delete from Table1 where col1 = 'a' AND col2 = 'b'");
$conn->exec("DROP TABLE Table1 ");
$conn = null;
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "select * from Person.ContactType";
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
print $stmt->rowCount();
print " rows in result set.";
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
1 rows affects.
20 rows in result set.

View file

@ -0,0 +1,25 @@
--TEST--
sets the query timeout attribute
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd", array('MultipleActiveResultSets'=>false ) );
$stmt = $conn->prepare('SELECT * FROM Person.ContactType');
echo "Attribute number for ATTR_CURSOR: ".$stmt->getAttribute( constant( "PDO::ATTR_CURSOR" ) );
echo "\n";
$stmt->setAttribute(PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 2);
echo "Attribute number for SQLSRV_ATTR_QUERY_TIMEOUT: ".$stmt->getAttribute( constant( "PDO::SQLSRV_ATTR_QUERY_TIMEOUT" ) );
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
Attribute number for ATTR_CURSOR: 0
Attribute number for SQLSRV_ATTR_QUERY_TIMEOUT: 2

View file

@ -0,0 +1,93 @@
--TEST--
specifies the fetch mode before fetching
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$stmt1 = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
while ( $row = $stmt1->fetch()) {
print($row['Name'] . "\n");
}
print( "\n---------- PDO::FETCH_ASSOC -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetch();
print_r( $result );
print( "\n---------- PDO::FETCH_NUM -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->setFetchMode(PDO::FETCH_NUM);
$result = $stmt->fetch();
print_r ($result );
print( "\n---------- PDO::FETCH_BOTH -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->setFetchMode(PDO::FETCH_BOTH);
$result = $stmt->fetch();
print_r( $result );
print( "\n---------- PDO::FETCH_LAZY -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->setFetchMode(PDO::FETCH_LAZY);
$result = $stmt->fetch();
print_r( $result );
print( "\n---------- PDO::FETCH_OBJ -------------\n" );
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
$stmt->setFetchMode(PDO::FETCH_OBJ);
$result = $stmt->fetch();
print $result->Name;
print( "\n \n" );
//free the statements and connection
$stmt1 = null;
$stmt = null;
$conn = null;
?>
--EXPECT--
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
---------- PDO::FETCH_ASSOC -------------
Array
(
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_NUM -------------
Array
(
[0] => 1
[1] => Accounting Manager
[2] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_BOTH -------------
Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_LAZY -------------
PDORow Object
(
[queryString] => select * from Person.ContactType where ContactTypeID < 5
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
---------- PDO::FETCH_OBJ -------------
Accounting Manager

View file

@ -0,0 +1,30 @@
--TEST--
starts a transaction, insert 2 rows and commit the transaction
--SKIPIF--
--FILE--
<?php
require('connect.inc');
//make connection and create a temporaty table in tempdb
$conn = new PDO( "sqlsrv:Server=$server; Database = tempdb ", "$uid", "$pwd");
$conn->exec("CREAtE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1)) ");
$conn->beginTransaction();
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'b') ");
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'c') ");
//revert the inserts
$ret = $conn->exec("delete from Table1 where col1 = 'a'");
$conn->commit();
// $conn->rollback();
echo $ret." rows affected";
//drop the created temp table
$conn->exec("DROP TABLE Table1 ");
//free statement and connection
$ret=NULL;
$conn=NULL;
?>
--EXPECT--
2 rows affected

View file

@ -0,0 +1,138 @@
--TEST--
connect to a server and specify a database
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$c = new PDO( "sqlsrv:Server=$server ; Database = $databaseName ", "$uid", "$pwd", array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));
$query = 'SELECT * FROM Person.ContactType';
$stmt = $c->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
print_r( $row );
}
$stmt=null;
$c = null;
?>
--EXPECT--
Array
(
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 2
[Name] => Assistant Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 3
[Name] => Assistant Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 4
[Name] => Coordinator Foreign Markets
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 5
[Name] => Export Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 6
[Name] => International Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 7
[Name] => Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 8
[Name] => Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 9
[Name] => Marketing Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 10
[Name] => Order Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 11
[Name] => Owner
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 12
[Name] => Owner/Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 13
[Name] => Product Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 14
[Name] => Purchasing Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 15
[Name] => Purchasing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 16
[Name] => Regional Account Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 17
[Name] => Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 18
[Name] => Sales Associate
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 19
[Name] => Sales Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 20
[Name] => Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,139 @@
--TEST--
connect to a server, specifying the database later
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$c = new PDO( "sqlsrv:Server=$server", "$uid", "$pwd");
$c->exec( "USE $databaseName");
$query = 'SELECT * FROM Person.ContactType';
$stmt = $c->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print_r( $row );
}
$stmt=null;
$c = null;
?>
--EXPECT--
Array
(
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 2
[Name] => Assistant Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 3
[Name] => Assistant Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 4
[Name] => Coordinator Foreign Markets
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 5
[Name] => Export Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 6
[Name] => International Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 7
[Name] => Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 8
[Name] => Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 9
[Name] => Marketing Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 10
[Name] => Order Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 11
[Name] => Owner
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 12
[Name] => Owner/Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 13
[Name] => Product Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 14
[Name] => Purchasing Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 15
[Name] => Purchasing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 16
[Name] => Regional Account Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 17
[Name] => Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 18
[Name] => Sales Associate
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 19
[Name] => Sales Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 20
[Name] => Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,148 @@
--TEST--
connect to a server, setting MARS to false
--SKIPIF--
--FILE--
<?php
require('connect.inc');
// Connect to the local server using Windows Authentication and AdventureWorks database
try {
$conn = new PDO( "sqlsrv:Server=$server ; Database = $databaseName ; MultipleActiveResultSets=false", "$uid", "$pwd");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
die( "Error connecting to SQL Server" );
}
$query = 'SELECT * FROM Person.ContactType';
$stmt = $conn->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print_r( $row );
}
$stmt=null;
$conn = null;
?>
--EXPECT--
Array
(
[ContactTypeID] => 1
[Name] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 2
[Name] => Assistant Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 3
[Name] => Assistant Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 4
[Name] => Coordinator Foreign Markets
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 5
[Name] => Export Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 6
[Name] => International Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 7
[Name] => Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 8
[Name] => Marketing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 9
[Name] => Marketing Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 10
[Name] => Order Administrator
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 11
[Name] => Owner
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 12
[Name] => Owner/Marketing Assistant
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 13
[Name] => Product Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 14
[Name] => Purchasing Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 15
[Name] => Purchasing Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 16
[Name] => Regional Account Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 17
[Name] => Sales Agent
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 18
[Name] => Sales Associate
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 19
[Name] => Sales Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
)
Array
(
[ContactTypeID] => 20
[Name] => Sales Representative
[ModifiedDate] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,18 @@
--TEST--
reports the error code of querying a misspelled column
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:Server=$server ; Database = $databaseName ", "$uid", "$pwd");
$query = "SELECT * FROM Person.Address where Cityx = 'Essen'";
$conn->query($query);
print $conn->errorCode();
//free the connection
$conn=null;
?>
--EXPECT--
42S22

View file

@ -0,0 +1,26 @@
--TEST--
reports the error info of querying a misspelled column
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:Server=$server ; Database = $databaseName ", "$uid", "$pwd");
$query = "SELECT * FROM Person.Address where Cityx = 'Essen'";
$conn->query($query);
print $conn->errorCode();
echo "\n";
print_r ($conn->errorInfo());
//free the connection
$conn=null;
?>
--EXPECTREGEX--
42S22
Array
\(
\[0\] => 42S22
\[1\] => 207
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Invalid column name 'Cityx'.
\)

View file

@ -0,0 +1,24 @@
--TEST--
execute a delete and reports how many rows were deleted
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$c = new PDO( "sqlsrv:Server=$server", "$uid", "$pwd");
$c->exec("use tempdb");
$c->exec("CREAtE TABLE Table1(col1 VARCHAR(100), col2 VARCHAR(100)) ");
$ret = $c->exec("insert into Table1 values('xxxyy', 'yyxx')");
$ret = $c->exec("delete from Table1 where col1 = 'xxxyy'");
echo $ret," rows affected";
$c->exec("DROP TABLE Table1 ");
//free the statement and connection
$ret=null;
$c=null;
?>
--EXPECT--
1 rows affected

View file

@ -0,0 +1,39 @@
--TEST--
shows the PDO::ATR_ERRMODE attribute, before and after changing its value
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:Server=$server ; Database = $databaseName", "$uid", "$pwd");
$attributes1 = array( "ERRMODE" );
foreach ( $attributes1 as $val ) {
echo "PDO::ATTR_$val: ";
var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));
}
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$attributes1 = array( "ERRMODE" );
foreach ( $attributes1 as $val ) {
echo "PDO::ATTR_$val: ";
var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));
}
// An example using PDO::ATTR_CLIENT_VERSION
print_r($conn->getAttribute( PDO::ATTR_CLIENT_VERSION ));
//free the connection
$conn=null;
?>
--EXPECTREGEX--
PDO::ATTR_ERRMODE: int\(0\)
PDO::ATTR_ERRMODE: int\(2\)
Array
\(
\[DriverDllName\] => msodbcsql[0-9]{2}\.dll|libmsodbcsql-[0-9]{2}\.[0-9]\.so\.[0-9]\.[0-9]
\[DriverODBCVer\] => [0-9]{1,2}\.[0-9]{1,2}
\[DriverVer\] => [0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}
\[ExtensionVer\] => [0-9]\.[0-9]\.[0-9](\-((rc)|(preview))(\.[0-9]+)?)?(\+[0-9]+)?
\)

View file

@ -0,0 +1,16 @@
--TEST--
check if sqlsrv is in the array of available PDO drivers
--SKIPIF--
--FILE--
<?php
$drivers = PDO::getAvailableDrivers();
if (in_array('sqlsrv', $drivers))
echo "sqlsrv found\n";
else
echo "sqlsrv not found\n";
echo "Done\n";
?>
--EXPECT--
sqlsrv found
Done

View file

@ -0,0 +1,36 @@
--TEST--
prepares a statement with parameter markers and forward-only (server-side) cursor
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
$conn->exec("CREAtE TABLE Table1(col1 VARCHAR(100), col2 VARCHAR(100))");
$col1 = 'a';
$col2 = 'b';
$query = "insert into Table1(col1, col2) values(?, ?)";
$stmt = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
$stmt->execute( array( $col1, $col2 ) );
print $stmt->rowCount();
echo " row affected\n";
$query = "insert into Table1(col1, col2) values(:col1, :col2)";
$stmt = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
$stmt->execute( array( ':col1' => $col1, ':col2' => $col2 ) );
print $stmt->rowCount();
echo " row affected\n";
// revert the inserts
$conn->exec("delete from Table1 where col1 = 'a' AND col2 = 'b'");
$conn->exec("DROP TABLE Table1 ");
$stmt = null;
$conn = null;
?>
--EXPECT--
1 row affected
1 row affected

View file

@ -0,0 +1,89 @@
--TEST--
prepares a statement with a client-side cursor
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "select * from Person.ContactType";
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
echo "\n";
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "$row[Name]\n";
}
echo "\n..\n";
$row = $stmt->fetch( PDO::FETCH_BOTH, PDO::FETCH_ORI_FIRST );
print_r($row);
$row = $stmt->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1 );
print "$row[Name]\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT );
print "$row[1]\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR );
print "$row[1]..\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 0 );
print_r($row);
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_LAST );
print_r($row);
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
Export Administrator
International Marketing Manager
Marketing Assistant
Marketing Manager
Marketing Representative
Order Administrator
Owner
Owner/Marketing Assistant
Product Manager
Purchasing Agent
Purchasing Manager
Regional Account Representative
Sales Agent
Sales Associate
Sales Manager
Sales Representative
..
Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
Assistant Sales Agent
Assistant Sales Representative
Assistant Sales Agent..
Array
(
[0] => 1
[1] => Accounting Manager
[2] => 2008-04-30 00:00:00.000
)
Array
(
[0] => 20
[1] => Sales Representative
[2] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,91 @@
--TEST--
prepares a statement with a client-side cursor and specifies scroll type to buffered
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$query = "select * from Person.ContactType";
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
print $stmt->rowCount();
echo "\n";
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print "$row[Name]\n";
}
echo "\n..\n";
$row = $stmt->fetch( PDO::FETCH_BOTH, PDO::FETCH_ORI_FIRST );
print_r($row);
$row = $stmt->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1 );
print "$row[Name]\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT );
print "$row[1]\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR );
print "$row[1]..\n";
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 0 );
print_r($row);
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_LAST );
print_r($row);
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
20
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
Export Administrator
International Marketing Manager
Marketing Assistant
Marketing Manager
Marketing Representative
Order Administrator
Owner
Owner/Marketing Assistant
Product Manager
Purchasing Agent
Purchasing Manager
Regional Account Representative
Sales Agent
Sales Associate
Sales Manager
Sales Representative
..
Array
(
[ContactTypeID] => 1
[0] => 1
[Name] => Accounting Manager
[1] => Accounting Manager
[ModifiedDate] => 2008-04-30 00:00:00.000
[2] => 2008-04-30 00:00:00.000
)
Assistant Sales Agent
Assistant Sales Representative
Assistant Sales Agent..
Array
(
[0] => 1
[1] => Accounting Manager
[2] => 2008-04-30 00:00:00.000
)
Array
(
[0] => 20
[1] => Sales Representative
[2] => 2008-04-30 00:00:00.000
)

View file

@ -0,0 +1,135 @@
--TEST--
default query; query for a column; query with a new class; query into an existing class
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 );
$query = 'select * from Person.ContactType';
// simple query
$stmt = $conn->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print_r( $row['Name'] ."\n" );
}
echo "\n........ query for a column ............\n";
// query for one column
$stmt = $conn->query( $query, PDO::FETCH_COLUMN, 1 );
while ( $row = $stmt->fetch() ){
echo "$row\n";
}
echo "\n........ query with a new class ............\n";
$query = 'select * from HumanResources.Department order by GroupName';
// query with a class
class cc {
function __construct( $arg ) {
echo "$arg";
}
function __toString() {
return $this->DepartmentID . "; " . $this->Name . "; " . $this->GroupName;
}
}
$stmt = $conn->query( $query, PDO::FETCH_CLASS, 'cc', array( "arg1 " ));
while ( $row = $stmt->fetch() ){
echo "$row\n";
}
echo "\n........ query into an existing class ............\n";
$c_obj = new cc( '' );
$stmt = $conn->query( $query, PDO::FETCH_INTO, $c_obj );
while ( $stmt->fetch() ){
echo "$c_obj\n";
}
$stmt = null;
$conn=null;
?>
--EXPECT--
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
Export Administrator
International Marketing Manager
Marketing Assistant
Marketing Manager
Marketing Representative
Order Administrator
Owner
Owner/Marketing Assistant
Product Manager
Purchasing Agent
Purchasing Manager
Regional Account Representative
Sales Agent
Sales Associate
Sales Manager
Sales Representative
........ query for a column ............
Accounting Manager
Assistant Sales Agent
Assistant Sales Representative
Coordinator Foreign Markets
Export Administrator
International Marketing Manager
Marketing Assistant
Marketing Manager
Marketing Representative
Order Administrator
Owner
Owner/Marketing Assistant
Product Manager
Purchasing Agent
Purchasing Manager
Regional Account Representative
Sales Agent
Sales Associate
Sales Manager
Sales Representative
........ query with a new class ............
arg1 9; Human Resources; Executive General and Administration
arg1 10; Finance; Executive General and Administration
arg1 11; Information Services; Executive General and Administration
arg1 14; Facilities and Maintenance; Executive General and Administration
arg1 16; Executive; Executive General and Administration
arg1 15; Shipping and Receiving; Inventory Management
arg1 5; Purchasing; Inventory Management
arg1 7; Production; Manufacturing
arg1 8; Production Control; Manufacturing
arg1 12; Document Control; Quality Assurance
arg1 13; Quality Assurance; Quality Assurance
arg1 6; Research and Development; Research and Development
arg1 1; Engineering; Research and Development
arg1 2; Tool Design; Research and Development
arg1 3; Sales; Sales and Marketing
arg1 4; Marketing; Sales and Marketing
........ query into an existing class ............
9; Human Resources; Executive General and Administration
10; Finance; Executive General and Administration
11; Information Services; Executive General and Administration
14; Facilities and Maintenance; Executive General and Administration
16; Executive; Executive General and Administration
15; Shipping and Receiving; Inventory Management
5; Purchasing; Inventory Management
7; Production; Manufacturing
8; Production Control; Manufacturing
12; Document Control; Quality Assurance
13; Quality Assurance; Quality Assurance
6; Research and Development; Research and Development
1; Engineering; Research and Development
2; Tool Design; Research and Development
3; Sales; Sales and Marketing
4; Marketing; Sales and Marketing

View file

@ -0,0 +1,42 @@
--TEST--
insert with quoted parameters
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
$conn->exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
$param = 'a \' g';
$param2 = $conn->quote( $param );
$query = "INSERT INTO Table1 VALUES( ?, '1' )";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
$query = "INSERT INTO Table1 VALUES( ?, ? )";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param, $param2));
$query = "SELECT * FROM Table1";
$stmt = $conn->query($query);
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print_r( $row['col1'] ." was inserted\n" );
}
// revert the inserts
$query = "delete from Table1 where col1 = ?";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
$conn->exec("DROP TABLE Table1 ");
//free the statement and connection
$stmt=null;
$conn=null;
?>
--EXPECT--
a ' g was inserted
a ' g was inserted

View file

@ -0,0 +1,29 @@
--TEST--
sets to PDO::ATTR_ERRMODE
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
$attributes1 = array( "ERRMODE" );
foreach ( $attributes1 as $val ) {
echo "PDO::ATTR_$val: ";
var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));
}
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$attributes1 = array( "ERRMODE" );
foreach ( $attributes1 as $val ) {
echo "PDO::ATTR_$val: ";
var_dump ($conn->getAttribute( constant( "PDO::ATTR_$val" ) ));
}
//free the connection
$conn=null;
?>
--EXPECT--
PDO::ATTR_ERRMODE: int(0)
PDO::ATTR_ERRMODE: int(2)

View file

@ -0,0 +1,42 @@
--TEST--
sets to PDO::SQLSRV_ATTR_DIRECT_QUERY
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO("sqlsrv:Server=$server", "$uid", "$pwd");
$conn->setAttribute(constant('PDO::SQLSRV_ATTR_DIRECT_QUERY'), true);
$stmt1 = $conn->query("DROP TABLE #php_test_table");
$stmt2 = $conn->query("CREATE TABLE #php_test_table ([c1_int] int, [c2_int] int)");
$v1 = 1;
$v2 = 2;
$stmt3 = $conn->prepare("INSERT INTO #php_test_table (c1_int, c2_int) VALUES (:var1, :var2)");
if ($stmt3) {
$stmt3->bindValue(1, $v1);
$stmt3->bindValue(2, $v2);
if ($stmt3->execute())
echo "Execution succeeded\n";
else
echo "Execution failed\n";
}
else
var_dump($conn->errorInfo());
$stmt4 = $conn->query("DROP TABLE #php_test_table");
// free the statements and connection
$stmt1=null;
$stmt2=null;
$stmt3=null;
$stmt4=null;
$conn=null;
?>
--EXPECT--
Execution succeeded

View file

@ -0,0 +1,61 @@
--TEST--
call a stored procedure and retrieve the errorNumber that is returned
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
// Drop the stored procedure if it already exists
$tsql_dropSP = "IF OBJECT_ID('sp_Test_Double', 'P') IS NOT NULL
DROP PROCEDURE sp_Test_Double";
$stmt = $conn->query($tsql_dropSP);
// Create the stored procedure
$tsql_createSP = "CREATE PROCEDURE sp_Test_Double
@ErrorNumber as float(53) = 0.0 OUTPUT
AS
BEGIN
SET @ErrorNumber = -1.111
SELECT 1, 2, 3
END";
$stmt = $conn->query($tsql_createSP);
// Call the stored procedure
$stmt = $conn->prepare("{CALL sp_Test_Double (?)}");
$errorNumber = 0.0;
$stmt->bindParam(1, $errorNumber, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 20);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_NUM);
$stmt->closeCursor();
print("Error Number: $errorNumber\n\n");
$value = $errorNumber - 2;
print("Error Number minus 2: $value\n\n");
print_r($result);
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
Error Number: -1.111
Error Number minus 2: -3.111
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)

View file

@ -0,0 +1,57 @@
--TEST--
call a stored procedure and retrieve the errorNumber that is returned
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
// Drop the stored procedure if it already exists
$tsql_dropSP = "IF OBJECT_ID('sp_Test_Integer', 'P') IS NOT NULL
DROP PROCEDURE sp_Test_Integer";
$stmt = $conn->query($tsql_dropSP);
// Create the stored procedure
$tsql_createSP = "CREATE PROCEDURE sp_Test_Integer
@ErrorNumber AS INT = 0 OUTPUT
AS
BEGIN
SET @ErrorNumber = -1
SELECT 1,2,3
END";
$stmt = $conn->query($tsql_createSP);
// Call the stored procedure
$stmt = $conn->prepare("{CALL sp_Test_Integer (:errornumber)}");
$errorNumber = 0;
$stmt->bindParam('errornumber', $errorNumber, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_NUM);
$stmt->closeCursor();
print("Error Number: $errorNumber\n\n");
print_r($result);
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
Error Number: -1
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)

View file

@ -0,0 +1,60 @@
--TEST--
call a stored procedure and retrieve the errorString that is returned
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
// Drop the stored procedure if it already exists
$tsql_dropSP = "IF OBJECT_ID('sp_Test_String', 'P') IS NOT NULL
DROP PROCEDURE sp_Test_String";
$stmt = $conn->query($tsql_dropSP);
// Create the stored procedure
$tsql_createSP = "CREATE PROCEDURE sp_Test_String
@ErrorString as varchar(20) OUTPUT
AS
BEGIN
SET @ErrorString = REVERSE(@ErrorString)
SELECT 1,2,3
END";
$stmt = $conn->query($tsql_createSP);
// Call the stored procedure
$stmt = $conn->prepare("{CALL sp_Test_String (?)}");
$errorString = "12345";
$stmt->bindParam(1, $errorString, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
print("Error String: $errorString\n\n");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_NUM);
$stmt->closeCursor();
print("Error String: $errorString\n\n");
print_r($result);
//free the statement and connection
$stmt = null;
$conn = null;
?>
--EXPECT--
Error String: 12345
Error String: 54321
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
)

View file

@ -0,0 +1,7 @@
This folder mainly contains tests that are derived from the code examples on
https://docs.microsoft.com/en-us/sql/connect/php/pdo-class
https://docs.microsoft.com/en-us/sql/connect/php/pdostatement-class
Modify connect.inc with the real credentials to run the tests, using the latest run-tests.php from
https://raw.githubusercontent.com/php/php-src/master/run-tests.php

106
test/bvt/sqlsrv/break.inc Normal file
View file

@ -0,0 +1,106 @@
<?php
// Set SQL server + user + password
$serverName = getenv('MSSQL_SERVERNAME') ?: "sql-2k14-sp2-1.galaxy.ad";
$username = getenv('MSSQL_USERNAME') ?: "sa";
$password = getenv('MSSQL_PASSWORD') ?: "Moonshine4me";
// Generate unique DB name, example: php_20160817_1471475608267
$databaseName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
// Generic table name example: php_20160817_1471475608267.dbo.php_firefly
$tableName1 = $databaseName.".dbo.php_firefly1";
$tableName2 = $databaseName.".dbo.php_firefly2";
$connectionInfo = array( "Database"=>"$databaseName", "username"=>"$username", "password"=>"$password" );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
// CREATE database
$stmt0 = sqlsrv_query($conn, "CREATE DATABASE $databaseName");
// Create table
$sql = "CREATE TABLE $tableName1 (c1 INT, c2 VARCHAR(40))";
$stmt = sqlsrv_query($conn, $sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName1 VALUES (?,?)";
for($t=100; $t<115; $t++) {
$stmt = sqlsrv_prepare($conn, $sql);
$ts = substr(sha1($t),0,5);
$params = array($t,$ts);
sqlsrv_execute($stmt, $params);
}
// Create table
$sql = "CREATE TABLE $tableName2 (c1 INT, c2 VARCHAR(40))";
$stmt = sqlsrv_query($conn, $sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName2 VALUES (?,?)";
for($t=200; $t<208; $t++) {
$stmt = sqlsrv_prepare($conn, $sql);
$ts = substr(sha1($t),0,5);
$params = array($t,$ts);
sqlsrv_execute($stmt, $params);
}
sqlsrv_close( $conn );
function RestartConn($serverName)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Stop()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
// Wait until the service is fully stopped
while (substr_count($servstring, "Stopped") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
}
$restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Start()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
// Wait until the service is fully started
while (substr_count($servstring, "Running") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
}
}
function StopConn($serverName)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Stop()";
exec( $restart_string );
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
// Wait until the service is fully stopped
while (substr_count($servstring, "Stopped") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
}
}
function StartConn($serverName)
{
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
if (substr_count($servstring, "Running") != 1)
{
$restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Start()";
exec( $restart_string );
}
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
// Wait until the service is fully started
while (substr_count($servstring, "Running") != 1)
{
sleep(1);
$servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
}
}
?>

88
test/bvt/sqlsrv/break.php Normal file
View file

@ -0,0 +1,88 @@
<?php
require_once("connect.inc");
// Using the tempdb database for two tables specifically constructed
// for the connection resiliency tests
$dbName = "tempdb";
$tableName1 = "test_connres1";
$tableName2 = "test_connres2";
// Generate tables for use with the connection resiliency tests.
// Using generated tables will eventually allow us to put the
// connection resiliency tests on Github, since the integrated testing
// from AppVeyor does not have AdventureWorks.
function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 )
{
$connectionInfo = array( "Database"=>$dbName, "uid"=>$uid, "pwd"=>$pwd );
$conn = sqlsrv_connect( $server, $connectionInfo );
if ( $conn === false )
{
die ( print_r( sqlsrv_errors() ) );
}
// Create table
$sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )";
$stmt = sqlsrv_query( $conn, $sql );
// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
for( $t = 100; $t < 116; $t++ )
{
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt = sqlsrv_prepare( $conn, $sql, $params );
sqlsrv_execute( $stmt );
}
// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$stmt = sqlsrv_query( $conn, $sql );
// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
for( $t = 200; $t < 209; $t++ )
{
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt = sqlsrv_prepare( $conn, $sql, $params );
sqlsrv_execute( $stmt );
}
sqlsrv_close( $conn );
}
// Break connection by getting the session ID and killing it.
// Note that breaking a connection and testing reconnection requires a
// TCP/IP protocol connection (as opposed to a Shared Memory protocol).
function BreakConnection( $conn, $conn_break )
{
$stmt1 = sqlsrv_query( $conn, "SELECT @@SPID" );
if ( sqlsrv_fetch( $stmt1 ) )
{
$spid=sqlsrv_get_field( $stmt1, 0 );
}
$stmt2 = sqlsrv_prepare( $conn_break, "KILL ".$spid );
sqlsrv_execute( $stmt2 );
sleep(1);
}
// Remove the tables generated by GenerateTables
function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
{
$connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd );
$conn = sqlsrv_connect( $server, $connectionInfo );
$query="IF OBJECT_ID('tempdb.dbo.$tableName1, 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName1";
$stmt=sqlsrv_query( $conn, $query );
$query="IF OBJECT_ID('tempdb.dbo.$tableName2, 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName2";
$stmt=sqlsrv_query( $conn, $query );
}
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 );
?>

View file

@ -0,0 +1,31 @@
<?php
$server = 'TARGET_SERVER';
$databaseName = 'TARGET_DATABASE';
$uid = 'TARGET_USERNAME';
$pwd = 'TARGET_PASSWORD';
// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
// changes are made to SalesOrderDetail. Since RevisionNumber is a tinyint, it can
// overflow quickly if the BVT tests often run. So we change it directly here first
// before it can overflow.
function ResetRevisionNumber( $server, $databaseName, $uid, $pwd )
{
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd );
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.<br>";
die( print_r( sqlsrv_errors(), true));
}
$stmt0 = sqlsrv_query( $conn, "UPDATE Sales.SalesOrderHeader SET RevisionNumber = 2");
if ( !$stmt0 )
{
echo "Resetting the RevisionNumber failed.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn );
}
?>

View file

@ -0,0 +1,74 @@
--TEST--
executes two queries as part of a transaction
--SKIPIF--
--FILE--
<?php
require('connect.inc');
// First, reset the RevisionNumber to make sure it won't overflow
ResetRevisionNumber( $server, $databaseName, $uid, $pwd );
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true ));
}
/* Initiate transaction. */
/* Exit script if transaction cannot be initiated. */
if ( sqlsrv_begin_transaction( $conn ) === false )
{
echo "Could not begin transaction.\n";
die( print_r( sqlsrv_errors(), true ));
}
/* Initialize parameter values. */
$orderId = 43659; $qty = 5; $productId = 709;
$offerId = 1; $price = 5.70;
/* Set up and execute the first query. */
$tsql1 = "INSERT INTO Sales.SalesOrderDetail
(SalesOrderID,
OrderQty,
ProductID,
SpecialOfferID,
UnitPrice)
VALUES (?, ?, ?, ?, ?)";
$params1 = array( $orderId, $qty, $productId, $offerId, $price);
$stmt1 = sqlsrv_query( $conn, $tsql1, $params1 );
/* Set up and execute the second query. */
$tsql2 = "UPDATE Production.ProductInventory
SET Quantity = (Quantity - ?)
WHERE ProductID = ?";
$params2 = array($qty, $productId);
$stmt2 = sqlsrv_query( $conn, $tsql2, $params2 );
/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if( $stmt1 && $stmt2 )
{
sqlsrv_commit( $conn );
echo "Transaction was committed.\n";
}
else
{
sqlsrv_rollback( $conn );
echo "Transaction was rolled back.\n";
}
/* Revert the changes */
$d_sql = "DELETE FROM Sales.SalesOrderDetail WHERE SalesOrderID=43659 AND OrderQty=5 AND ProductID=709 AND SpecialOfferID=1 AND Unitprice=5.70";
$stmt3 = sqlsrv_query($conn, $d_sql);
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt1);
sqlsrv_free_stmt( $stmt2);
sqlsrv_free_stmt($stmt3);
sqlsrv_close( $conn);
?>
--EXPECT--
Transaction was committed.

View file

@ -0,0 +1,78 @@
--TEST--
delete in a transaction
--SKIPIF--
--FILE--
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Begin transaction. */
if( sqlsrv_begin_transaction($conn) === false )
{
echo "Could not begin transaction.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Set the Order ID. */
$orderId = 43667;
/* Execute operations that are part of the transaction. Commit on
success, roll back on failure. */
if (perform_trans_ops($conn, $orderId))
{
//If commit fails, roll back the transaction.
if(sqlsrv_commit($conn))
{
echo "Transaction committed.\n";
}
else
{
echo "Commit failed - rolling back.\n";
sqlsrv_rollback($conn);
}
}
else
{
"Error in transaction operation - rolling back.\n";
sqlsrv_rollback($conn);
}
/*Free connection resources*/
sqlsrv_close( $conn);
/*---------------- FUNCTION: perform_trans_ops -----------------*/
function perform_trans_ops($conn, $orderId)
{
/* Define query to update inventory based on sales order info. */
$tsql1 = "UPDATE Production.ProductInventory
SET Quantity = Quantity + s.OrderQty
FROM Production.ProductInventory p
JOIN Sales.SalesOrderDetail s
ON s.ProductID = p.ProductID
WHERE s.SalesOrderID = ?";
/* Define the parameters array. */
$params = array($orderId);
/* Execute the UPDATE statement. Return false on failure. */
if( sqlsrv_query( $conn, $tsql1, $params) === false ) return false;
/* Delete the sales order. Return false on failure */
$tsql2 = "DELETE FROM Sales.SalesOrderDetail
WHERE SalesOrderID = ?";
if(sqlsrv_query( $conn, $tsql2, $params) === false ) return false;
/* Return true because all operations were successful. */
return true;
}
?>
--EXPECT--
Transaction committed.

View file

@ -0,0 +1,49 @@
--TEST--
executes a query, then comsumes and counts results until reaches a specified amount. The remaining query results are then discarded.
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare and execute the query. */
$tsql = "SELECT OrderQty, UnitPrice FROM Sales.SalesOrderDetail ORDER BY SalesOrderID";
$stmt = sqlsrv_prepare( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation.\n";
die( print_r( sqlsrv_errors(), true));
}
if( sqlsrv_execute( $stmt ) === false)
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Initialize tracking variables. */
$salesTotal = 0;
$count = 0;
/* Count and display the number of sales that produce revenue
of $100,000. */
while( ($row = sqlsrv_fetch_array( $stmt)) && $salesTotal <=100000)
{
$qty = $row[0];
$price = $row[1];
$salesTotal += ( $price * $qty);
$count++;
}
echo "$count sales accounted for the first $$salesTotal in revenue.\n";
/* Cancel the pending results. The statement can be reused. */
sqlsrv_cancel( $stmt);
?>
--EXPECT--
57 sales accounted for the first $104171.7607 in revenue.

View file

@ -0,0 +1,80 @@
--TEST--
cancels a statement then reuse.
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare and execute the query. */
echo "<h4>SELECT : Scrollable => SQLSRV_CURSOR_KEYSET</h4>";
$sql = "SELECT * FROM Person.Address";
// $tsql = "SELECT * FROM HumanResources.Employee";
$params = array();
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$options = array();
$stmt = sqlsrv_query($conn, $sql, $params, $options);
// sqlsrv_execute ( $stmt );
// $stmt = sqlsrv_query( $conn, $sql, array(), array() );
// PRINT RESULT SET
$numRowsPrint = 3;
echo "<h4>Printing first $numRowsPrint rows</h4>";
echo "<p><table cellpadding=3 border=1 cellspacing=4>";
$count = 0;
// while( ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) && $count <$numRowsPrint)
while( ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)) && $count <$numRowsPrint)
{
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "</tr>";
$count++;
}
echo "</table>";
/* Cancel the pending results. The statement can be reused. */
sqlsrv_cancel( $stmt);
// PRINT RESULT SET
echo "<h4>SQLSRV_CANCEL + Print next 5 rows of the result set (MUST BE EMPTY)</h4>";
echo "<p><table cellpadding=3 border=1 cellspacing=4>";
while( ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC)) && $count <($numRowsPrint + 5))
{
echo "<p><font color=red>IF sqlsrv_cancel() is executed, YOU SHOUL NOT SEE THIS</font>";
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "</tr>";
$count++;
}
echo "</table>";
echo "<p><font color=green>Finished successfully</font>";
?>
--EXPECT--
<h4>SELECT : Scrollable => SQLSRV_CURSOR_KEYSET</h4><h4>Printing first 3 rows</h4><p><table cellpadding=3 border=1 cellspacing=4><tr><td>1</td><td>1970 Napa Ct.</td><td></td><td>Bothell</td><td>79</td><td>9AADCB0D-36CF-483F-84D8-585C2D4EC6E9</td></tr><tr><td>2</td><td>9833 Mt. Dias Blv.</td><td></td><td>Bothell</td><td>79</td><td>32A54B9E-E034-4BFB-B573-A71CDE60D8C0</td></tr><tr><td>3</td><td>7484 Roundtree Drive</td><td></td><td>Bothell</td><td>79</td><td>4C506923-6D1B-452C-A07C-BAA6F5B142A4</td></tr></table><h4>SQLSRV_CANCEL + Print next 5 rows of the result set (MUST BE EMPTY)</h4><p><table cellpadding=3 border=1 cellspacing=4></table><p><font color=green>Finished successfully</font>

View file

@ -0,0 +1,35 @@
--TEST--
client information.
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
if( $client_info = sqlsrv_client_info( $conn))
{
foreach( $client_info as $key => $value)
{
echo $key.": ".$value."\n";
}
}
else
{
echo "Client info error.\n";
}
/* Close connection resources. */
sqlsrv_close( $conn);
?>
--EXPECTREGEX--
DriverDllName: msodbcsql[0-9]{2}\.dll|libmsodbcsql-[0-9]{2}\.[0-9]\.so\.[0-9]\.[0-9]
DriverODBCVer: [0-9]{1,2}\.[0-9]{1,2}
DriverVer: [0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}
ExtensionVer: [0-9]\.[0-9]\.[0-9](\-((rc)|(preview))(\.[0-9]+)?)?(\+[0-9]+)?

View file

@ -0,0 +1,35 @@
--TEST--
closes a connection.
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare and execute the query. */
$tsql = "SELECT OrderQty, UnitPrice FROM Sales.SalesOrderDetail";
$stmt = sqlsrv_prepare( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation.\n";
die( print_r( sqlsrv_errors(), true));
}
if( sqlsrv_execute( $stmt ) === false)
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Close the connection. */
sqlsrv_close( $conn);
echo "Connection closed.\n";
?>
--EXPECT--
Connection closed.

View file

@ -0,0 +1,71 @@
--TEST--
executes two queries as part of a transaction. If both queries are successful, the transaction is committed.
--SKIPIF--
?>
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true ));
}
/* Initiate transaction. */
/* Exit script if transaction cannot be initiated. */
if (sqlsrv_begin_transaction( $conn) === false)
{
echo "Could not begin transaction.\n";
die( print_r( sqlsrv_errors(), true ));
}
/* Initialize parameter values. */
$orderId = 43659; $qty = 5; $productId = 709;
$offerId = 1; $price = 5.70;
/* Set up and execute the first query. */
$tsql1 = "INSERT INTO Sales.SalesOrderDetail
(SalesOrderID,
OrderQty,
ProductID,
SpecialOfferID,
UnitPrice)
VALUES (?, ?, ?, ?, ?)";
$params1 = array( $orderId, $qty, $productId, $offerId, $price);
$stmt1 = sqlsrv_query( $conn, $tsql1, $params1 );
/* Set up and execute the second query. */
$tsql2 = "UPDATE Production.ProductInventory
SET Quantity = (Quantity - ?)
WHERE ProductID = ?";
$params2 = array($qty, $productId);
$stmt2 = sqlsrv_query( $conn, $tsql2, $params2 );
/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if( $stmt1 && $stmt2 )
{
sqlsrv_commit( $conn );
echo "Transaction was committed.\n";
}
else
{
sqlsrv_rollback( $conn );
echo "Transaction was rolled back.\n";
}
/* Revert the changes */
$d_sql = "DELETE FROM Sales.SalesOrderDetail WHERE SalesOrderID=43659 AND OrderQty=5 AND ProductID=709 AND SpecialOfferID=1 AND Unitprice=5.70";
$stmt3 = sqlsrv_query($conn, $d_sql);
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt1);
sqlsrv_free_stmt( $stmt2);
sqlsrv_free_stmt($stmt3);
sqlsrv_close( $conn);
?>
--EXPECT--
Transaction was committed.

View file

@ -0,0 +1,69 @@
--TEST--
disables the default error-handling behaviour using configure
--SKIPIF--
?>
--FILE--
<?php
/* Connect to the local server using Windows Authentication. */
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* The Transact-SQL PRINT statement can be used to return
informational or warning messages*/
$tsql = "PRINT 'The PRINT statement can be used ";
$tsql .= "to return user-defined warnings.'";
/* Execute the query and print any errors. */
$stmt1 = sqlsrv_query( $conn, $tsql);
if($stmt1 === false)
{
echo "By default, warnings are treated as errors:\n";
/* Dump errors in the error collection. */
print_r(sqlsrv_errors(SQLSRV_ERR_ERRORS));
}
/* Disable warnings as errors behavior. */
sqlsrv_configure("WarningsReturnAsErrors", 0);
/* Execute the same query and print any errors. */
$stmt2 = sqlsrv_query( $conn, $tsql);
if($stmt2 === false)
{
/* Dump errors in the error collection. */
/* Since the warning generated by the query will not be treated as
an error, this block of code will not be executed. */
print_r(sqlsrv_errors(SQLSRV_ERR_ERRORS));
}
else
{
echo "After calling ";
echo "sqlsrv_configure('WarningsReturnAsErrors', 0), ";
echo "warnings are not treated as errors.";
}
/*Close the connection. */
sqlsrv_close($conn);
?>
--EXPECTREGEX--
By default, warnings are treated as errors:
Array
\(
\[0\] => Array
\(
\[0\] => 01000
\[SQLSTATE\] => 01000
\[1\] => 0
\[code\] => 0
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The PRINT statement can be used to return user-defined warnings.
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The PRINT statement can be used to return user-defined warnings.
\)
\)
After calling sqlsrv_configure\('WarningsReturnAsErrors', 0\), warnings are not treated as errors.

View file

@ -0,0 +1,178 @@
--TEST--
disables the default error-handling behaviour using configure and returns warnings
--SKIPIF--
--FILE--
<?php
/* Turn off the default behavior of treating errors as warnings.
Note: Turning off the default behavior is done here for demonstration
purposes only. If setting the configuration fails, display errors and
exit the script. */
if( sqlsrv_configure("WarningsReturnAsErrors", 0) === false)
{
DisplayErrors();
die;
}
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
/* If the connection fails, display errors and exit the script. */
if( $conn === false )
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/* Revert previous updates */
$r_sql="UPDATE HumanResources.Employee SET VacationHours=61 WHERE BusinessEntityID=7;
UPDATE HumanResources.Employee SET VacationHours=62 WHERE BusinessEntityID=8;
UPDATE HumanResources.Employee SET VacationHours=63 WHERE BusinessEntityID=9;
UPDATE HumanResources.Employee SET VacationHours=7 WHERE BusinessEntityID=11";
$stmt4=sqlsrv_query($conn, $r_sql);
sqlsrv_free_stmt( $stmt4 );
/* Drop the stored procedure if it already exists. */
$tsql1 = "IF OBJECT_ID('SubtractVacationHours', 'P') IS NOT NULL
DROP PROCEDURE SubtractVacationHours";
$stmt1 = sqlsrv_query($conn, $tsql1);
/* If the query fails, display errors and exit the script. */
if( $stmt1 === false)
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/* Free the statement resources. */
sqlsrv_free_stmt( $stmt1 );
/* Create the stored procedure. */
$tsql2 = "CREATE PROCEDURE SubtractVacationHours
@BusinessEntityId int,
@VacationHours smallint OUTPUT
AS
UPDATE HumanResources.Employee
SET VacationHours = VacationHours - @VacationHours
WHERE BusinessEntityId = @BusinessEntityId;
SET @VacationHours = (SELECT VacationHours
FROM HumanResources.Employee
WHERE BusinessEntityId = @BusinessEntityId);
IF @VacationHours < 0
BEGIN
PRINT 'WARNING: Vacation hours are now less than zero.'
END;";
$stmt2 = sqlsrv_query( $conn, $tsql2 );
/* If the query fails, display errors and exit the script. */
if( $stmt2 === false)
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/* Free the statement resources. */
sqlsrv_free_stmt( $stmt2 );
/* Set up the array that maps employee ID to used vacation hours. */
$emp_hrs = array (7=>4, 8=>5, 9=>8, 11=>50);
/* Initialize variables that will be used as parameters. */
$businessEntityId = 0;
$vacationHrs = 0;
/* Set up the parameter array. */
$params = array(
array(&$businessEntityId, SQLSRV_PARAM_IN),
array(&$vacationHrs, SQLSRV_PARAM_INOUT)
);
/* Define and prepare the query to substract used vacation hours. */
$tsql3 = "{call SubtractVacationHours(?, ?)}";
$stmt3 = sqlsrv_prepare($conn, $tsql3, $params);
/* If the statement preparation fails, display errors and exit the script. */
if( $stmt3 === false)
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/* Loop through the employee=>vacation hours array. Update parameter
values before statement execution. */
foreach(array_keys($emp_hrs) as $businessEntityId)
{
$vacationHrs = $emp_hrs[$businessEntityId];
/* Execute the query. If it fails, display the errors. */
if( sqlsrv_execute($stmt3) === false)
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/*Move to the next result returned by the stored procedure. */
if( sqlsrv_next_result($stmt3) === false)
{
DisplayErrors();
die;
}
/* Display any warnings. */
DisplayWarnings();
/* Display updated vacation hours. */
echo "BusinessEntityId $businessEntityId has $vacationHrs ";
echo "remaining vacation hours.\n";
}
/* Free the statement*/
sqlsrv_free_stmt( $stmt3 );
/* close connection resources. */
sqlsrv_close( $conn );
/* ------------- Error Handling Functions --------------*/
function DisplayErrors()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
foreach( $errors as $error )
{
echo "Error: ".$error['message']."\n";
}
}
function DisplayWarnings()
{
$warnings = sqlsrv_errors(SQLSRV_ERR_WARNINGS);
if(!is_null($warnings))
{
foreach( $warnings as $warning )
{
$message = $warning['message'];
// Skips the message with 'unixODBC' (an unnecessary duplicate message in some platform)
if (! stripos($message, 'unixODBC') )
echo "Warning: $message\n";
}
}
}
?>
--EXPECTREGEX--
Warning: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Changed database context to 'AdventureWorks2014'.
Warning: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Changed language setting to us_english.
BusinessEntityId 7 has 57 remaining vacation hours.
BusinessEntityId 8 has 57 remaining vacation hours.
BusinessEntityId 9 has 55 remaining vacation hours.
Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The UPDATE statement conflicted with the CHECK constraint "CK_Employee_VacationHours". The conflict occurred in database "AdventureWorks2014", table "HumanResources.Employee", column 'VacationHours'.
Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The statement has been terminated.

View file

@ -0,0 +1,39 @@
--TEST--
creates and opens a connection using Windows Authentication.
--SKIPIF--
--FILE--
<?php
require('connect.inc');
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare and execute the query. */
$tsql = "SELECT OrderQty, UnitPrice FROM Sales.SalesOrderDetail";
$stmt = sqlsrv_prepare( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation.\n";
die( print_r( sqlsrv_errors(), true));
}
if( sqlsrv_execute( $stmt ) === false)
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Close the connection. */
sqlsrv_close( $conn);
?>
--EXPECT--
Connection established.

Some files were not shown because too many files have changed in this diff Show more