From 1ce857a993acc1977a67d7f20592e0cee0513142 Mon Sep 17 00:00:00 2001 From: Jonathan Guerin Date: Tue, 12 Jul 2011 17:41:34 +0000 Subject: [PATCH] First commit First commit for the SQLSRV and PDO_SQLSRV extension documentation. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313179 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/pdo/drivers.xml | 5 + reference/pdo_sqlsrv/configure.xml | 47 + reference/pdo_sqlsrv/constants.xml | 179 ++++ reference/pdo_sqlsrv/reference.xml | 225 ++++ reference/sqlsrv/book.xml | 48 + reference/sqlsrv/configure.xml | 47 + reference/sqlsrv/constants.xml | 982 ++++++++++++++++++ reference/sqlsrv/entities.functions.xml | 26 + .../functions/sqlsrv-begin-transaction.xml | 136 +++ reference/sqlsrv/functions/sqlsrv-cancel.xml | 137 +++ .../sqlsrv/functions/sqlsrv-client-info.xml | 131 +++ reference/sqlsrv/functions/sqlsrv-close.xml | 99 ++ reference/sqlsrv/functions/sqlsrv-commit.xml | 136 +++ .../sqlsrv/functions/sqlsrv-configure.xml | 115 ++ reference/sqlsrv/functions/sqlsrv-connect.xml | 177 ++++ reference/sqlsrv/functions/sqlsrv-errors.xml | 159 +++ reference/sqlsrv/functions/sqlsrv-execute.xml | 136 +++ .../sqlsrv/functions/sqlsrv-fetch-array.xml | 186 ++++ .../sqlsrv/functions/sqlsrv-fetch-object.xml | 190 ++++ reference/sqlsrv/functions/sqlsrv-fetch.xml | 155 +++ .../functions/sqlsrv-field-metadata.xml | 149 +++ .../sqlsrv/functions/sqlsrv-free-stmt.xml | 121 +++ .../sqlsrv/functions/sqlsrv-get-config.xml | 73 ++ .../sqlsrv/functions/sqlsrv-get-field.xml | 146 +++ .../sqlsrv/functions/sqlsrv-has-rows.xml | 102 ++ .../sqlsrv/functions/sqlsrv-next-result.xml | 120 +++ .../sqlsrv/functions/sqlsrv-num-fields.xml | 113 ++ .../sqlsrv/functions/sqlsrv-num-rows.xml | 111 ++ reference/sqlsrv/functions/sqlsrv-prepare.xml | 237 +++++ reference/sqlsrv/functions/sqlsrv-query.xml | 213 ++++ .../sqlsrv/functions/sqlsrv-rollback.xml | 130 +++ .../sqlsrv/functions/sqlsrv-rows-affected.xml | 112 ++ .../functions/sqlsrv-send-stream-data.xml | 117 +++ .../sqlsrv/functions/sqlsrv-server-info.xml | 122 +++ reference/sqlsrv/ini.xml | 85 ++ reference/sqlsrv/reference.xml | 38 + reference/sqlsrv/setup.xml | 99 ++ 37 files changed, 5404 insertions(+) create mode 100644 reference/pdo_sqlsrv/configure.xml create mode 100644 reference/pdo_sqlsrv/constants.xml create mode 100644 reference/pdo_sqlsrv/reference.xml create mode 100644 reference/sqlsrv/book.xml create mode 100644 reference/sqlsrv/configure.xml create mode 100644 reference/sqlsrv/constants.xml create mode 100644 reference/sqlsrv/entities.functions.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-begin-transaction.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-cancel.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-client-info.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-close.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-commit.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-configure.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-connect.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-errors.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-execute.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-fetch-array.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-fetch-object.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-fetch.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-field-metadata.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-free-stmt.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-get-config.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-get-field.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-has-rows.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-next-result.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-num-fields.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-num-rows.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-prepare.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-query.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-rollback.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-rows-affected.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-send-stream-data.xml create mode 100644 reference/sqlsrv/functions/sqlsrv-server-info.xml create mode 100644 reference/sqlsrv/ini.xml create mode 100644 reference/sqlsrv/reference.xml create mode 100644 reference/sqlsrv/setup.xml diff --git a/reference/pdo/drivers.xml b/reference/pdo/drivers.xml index 631f47b663..5c32d8c7a7 100644 --- a/reference/pdo/drivers.xml +++ b/reference/pdo/drivers.xml @@ -57,6 +57,10 @@ PDO_SQLITE SQLite 3 and SQLite 2 + + + PDO_SQLSRV + Microsoft SQL Server / SQL Azure PDO_4D @@ -74,6 +78,7 @@ &reference.pdo-ibm.reference; &reference.pdo-informix.reference; &reference.pdo-mysql.reference; + &reference.pdo-sqlsrv.reference; &reference.pdo-oci.reference; &reference.pdo-odbc.reference; &reference.pdo-pgsql.reference; diff --git a/reference/pdo_sqlsrv/configure.xml b/reference/pdo_sqlsrv/configure.xml new file mode 100644 index 0000000000..b341e9c2f8 --- /dev/null +++ b/reference/pdo_sqlsrv/configure.xml @@ -0,0 +1,47 @@ + + +
+ &reftitle.install; + + The PDO_SQLSRV extension is enabled by adding appropriate DLL file to your PHP + extension directory and the corresponding entry to the &php.ini; file. The + PDO_SQLSRV download comes with several driver files. Which driver file you + use will depend on 3 factors: the PHP version you are using, whether you are + using thread-safe or non-thread-safe PHP, and whether your PHP installation + was compiled with the VC6 or VC9 compiler. For example, if you are running + PHP 5.3, you are using non-thread-safe PHP, and your PHP installation was + compiled with the VC9 compiler, you should use the php_pdo_sqlsrv_53_nts_vc9.dll + file. (You should use a non-thread-safe version compiled with the VC9 compiler + if you are using IIS as your web server). If you are running PHP 5.2, you are + using thread-safe PHP, and your PHP installation was compiled with the VC6 + compiler, you should use the php_pdo_sqlsrv_52_ts_vc6.dll file. + + + For more information about system requirements, see + SQLSRV System Requirements. + + + The PDO_SQLSRV extension is only compatible with PHP running on Windows. + +
+ + diff --git a/reference/pdo_sqlsrv/constants.xml b/reference/pdo_sqlsrv/constants.xml new file mode 100644 index 0000000000..bd6c2a4961 --- /dev/null +++ b/reference/pdo_sqlsrv/constants.xml @@ -0,0 +1,179 @@ + + +
+ &reftitle.constants; + &pdo.driver-constants; + + + + PDO::SQLSRV_TXN_READ_UNCOMMITTED + (integer) + + + + This constant is an acceptable value for the SQLSRV DSN key TransactionIsolation. + This constant sets the transaction isolation level for the connection to + Read Uncommitted. + + + + + + PDO::SQLSRV_TXN_READ_COMMITTED + (integer) + + + + This constant is an acceptable value for the SQLSRV DSN key TransactionIsolation. + This constant sets the transaction isolation level for the connection to + Read Committed. + + + + + + PDO::SQLSRV_TXN_REPEATABLE_READ + (integer) + + + + This constant is an acceptable value for the SQLSRV DSN key TransactionIsolation. + This constant sets the transaction isolation level for the connection to + Repeateable Read. + + + + + + PDO::SQLSRV_TXN_SNAPSHOT + (integer) + + + + This constant is an acceptable value for the SQLSRV DSN key TransactionIsolation. + This constant sets the transaction isolation level for the connection to Snapshot. + + + + + + PDO::SQLSRV_TXN_SERIALIZABLE + (integer) + + + + This constant is an acceptable value for the SQLSRV DSN key TransactionIsolation. + This constant sets the transaction isolation level for the connection to + Serializable. + + + + + + PDO::SQLSRV_ENCODING_BINARY + (integer) + + + + Specifies that data is sent/retrieved as a raw byte stream to/from the server + without performing encoding or translation. This constant can be passed to + PDOStatement::setAttribute, PDO::prepare, PDOStatement::bindColumn, and + PDOStatement::bindParam. + + + + + + PDO::SQLSRV_ENCODING_SYSTEM + (integer) + + + + Specifies that data is sent/retrieved to/from the server as 8-bit characters + as specified in the code page of the Windows locale that is set on the system. + Any multi-byte characters or characters that do not map into this code page + are substituted with a single byte question mark (?) character. This constant + can be passed to PDOStatement::setAttribute, PDO::setAttribute, PDO::prepare, + PDOStatement::bindColumn, and PDOStatement::bindParam. + + + + + + PDO::SQLSRV_ENCODING_UTF8 + (integer) + + + + Specifies that data is sent/retrieved to/from the server in UTF-8 encoding. + This is the default encoding. This constant can be passed to + PDOStatement::setAttribute, PDO::setAttribute, PDO::prepare, + PDOStatement::bindColumn, and PDOStatement::bindParam. + + + + + + PDO::SQLSRV_ENCODING_DEFAULT + (integer) + + + + Specifies that data is sent/retrieved to/from the server according to + PDO::SQLSRV_ENCODING_SYSTEM if specified during connection. The connection's + encoding is used if specified in a prepare statement. This constant can be + passed to PDOStatement::setAttribute, PDO::setAttribute, PDO::prepare, + PDOStatement::bindColumn, and PDOStatement::bindParam. + + + + + + PDO::SQLSRV_ATTR_QUERY_TIMEOUT + (integer) + + + + A non-negative integer representing the timeout period, in seconds. Zero (0) + is the default and means no timeout. This constant can be passed to + PDOStatement::setAttribute, PDO::setAttribute, and PDO::prepare. + + + + + + PDO::SQLSRV_ATTR_DIRECT_QUERY + (integer) + + + + Indicates that a query should be executed directly, without being prepared. + This constant can be passed to PDO::setAttribute, and PDO::prepare. For more + information, see + Direct and Prepared Statement Execution. + + + + +
+ + diff --git a/reference/pdo_sqlsrv/reference.xml b/reference/pdo_sqlsrv/reference.xml new file mode 100644 index 0000000000..176b32c597 --- /dev/null +++ b/reference/pdo_sqlsrv/reference.xml @@ -0,0 +1,225 @@ + + + + + + + Microsoft SQL Server Functions (PDO_SQLSRV) + MS SQL Server (PDO) + + +
+ &reftitle.intro; + + PDO_SQLSRV is a driver that implements the PHP + Data Objects (PDO) interface + to enable access from PHP to MS SQL Server (starting with SQL Server 2005) + and SQL Azure databases. + +
+ &reference.pdo-sqlsrv.configure; + &reference.pdo-sqlsrv.constants; +
+ + + + PDO_SQLSRV DSN + Connecting to MS SQL Server and SQL Azure databases + + + + &reftitle.description; + + The PDO_SQLSRV Data Source Name (DSN) is composed of the following elements: + + + DSN prefix + + + The DSN prefix is sqlsrv:. + + + + + APP + + + The application name used in tracing. + + + + + ConnectionPooling + + + Specifies whether the connection is assigned from a connection pool + (1 or &true;) or not (0 or &false;). + + + + + Database + + + The name of the database. + + + + + Encrypt + + + Specifies whether the communication with SQL Server is encrypted + (1 or &true;) or unencrypted (0 or &false;). + + + + + Failover_Partner + + + Specifies the server and instance of the database's mirror (if enabled + and configured) to use when the primary server is unavailable. + + + + + LoginTimeout + + + Specifies the number of seconds to wait before failing the connection attempt. + + + + + MultipleActiveResultSets + + + Disables or explicitly enables support for multiple active Result sets (MARS). + + + + + QuotedId + + + Specifies whether to use SQL-92 rules for quoted identifiers (1 or &true;) + or to use legacy Transact-SQL rules (0 or false). + + + + + Server + + + The name of the database server. + + + + + TraceFile + + + Specifies the path for the file used for trace data. + + + + + TraceOn + + + Specifies whether ODBC tracing is enabled (1 or &true;) or disabled + (0 or &false;) for the connection being established. + + + + + TransactionIsolation + + + Specifies the transaction isolation level. The accepted values for this + option are PDO::SQLSRV_TXN_READ_UNCOMMITTED, PDO::SQLSRV_TXN_READ_COMMITTED, + PDO::SQLSRV_TXN_REPEATABLE_READ, PDO::SQLSRV_TXN_SNAPSHOT, and + PDO::SQLSRV_TXN_SERIALIZABLE. + + + + + TrustServerCertificate + + + Specifies whether the client should trust (1 or &true;) or reject + (0 or &false;) a self-signed server certificate. + + + + + WSID + + + Specifies the name of the computer for tracing. + + + + + + + + + &reftitle.examples; + + + PDO_SQLSRV DSN examples + + The following example shows how to connecto to a specified MS SQL Server database: + + + + + + The following example shows how to connect to a MS SQL Server database on + a specified port: + + + + + + The following example shows how to connecto to a SQL Azure database with + server ID 12345abcde. Note that when you connect to SQL Azure with PDO, + your username will be UserName@12345abcde (UserName@ServerId). + + + + + + + + + +
+ diff --git a/reference/sqlsrv/book.xml b/reference/sqlsrv/book.xml new file mode 100644 index 0000000000..6b6ab20bb1 --- /dev/null +++ b/reference/sqlsrv/book.xml @@ -0,0 +1,48 @@ + + + + + Microsoft SQL Server Driver for PHP + SQLSRV + + + + &reftitle.intro; + + The SQLSRV extension allows you to access Microsoft SQL Server and SQL Azure + databases when running PHP on Windows. + + + The SQLSRV extension is supported by Microsoft and available for download here: + &url.sqlsrv;. + + + + + &reference.sqlsrv.setup; + &reference.sqlsrv.constants; + &reference.sqlsrv.reference; + + + + + diff --git a/reference/sqlsrv/configure.xml b/reference/sqlsrv/configure.xml new file mode 100644 index 0000000000..0048b5ea94 --- /dev/null +++ b/reference/sqlsrv/configure.xml @@ -0,0 +1,47 @@ + + +
+ &reftitle.install; + + The SQLSRV extension is enabled by adding appropriate DLL file to your PHP + extension directory and the corresponding entry to the &php.ini; file. The + SQLSRV download comes with several driver files. Which driver file you use + will depend on 3 factors: the PHP version you are using, whether you are using + thread-safe or non-thread-safe PHP, and whether your PHP installation was + compiled with the VC6 or VC9 compiler. For example, if you are running PHP 5.3, + you are using non-thread-safe PHP, and your PHP installation was compiled with + the VC9 compiler, you should use the php_sqlsrv_53_nts_vc9.dll file. (You should + use a non-thread-safe version compiled with the VC9 compiler if you are using + IIS as your web server). If you are running PHP 5.2, you are using thread-safe + PHP, and your PHP installation was compiled with the VC6 compiler, you should + use the php_sqlsrv_52_ts_vc6.dll file. + + + For more information about SQLSRV requirements, see + SQLSRV System Requirements. + + + The SQLSRV extension is only compatible with PHP running on Windows. + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/constants.xml b/reference/sqlsrv/constants.xml new file mode 100644 index 0000000000..a73b190d49 --- /dev/null +++ b/reference/sqlsrv/constants.xml @@ -0,0 +1,982 @@ + + + + &reftitle.constants; + &extension.constants; + + + + + SQLSRV_FETCH_ASSOC + (integer) + + + + Forces sqlsrv_fetch_array to return an associative + array when passed as a parameter. + + + + + + SQLSRV_FETCH_NUMERIC + (integer) + + + + Forces sqlsrv_fetch_array to return an array with + numeric when passed as a parameter. + + + + + + SQLSRV_FETCH_BOTH + (integer) + + + + Forces sqlsrv_fetch_array to return an array with both + associative and numeric keys when passed as a parameter (the default behavior). + + + + + + SQLSRV_ERR_ALL + (integer) + + + + Forces sqlsrv_errors to return both errors and warings + when passed as a parameter (the default behavior). + + + + + + SQLSRV_ERR_ERRORS + (integer) + + + + Forces sqlsrv_errors to return errors only (no warnings) + when passed as a parameter. + + + + + + SQLSRV_ERR_WARNINGS + (integer) + + + + Forces sqlsrv_errors to return warnings only (no errors) + when passed as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_ALL + (integer) + + + + Turns on logging of all subsystems when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_CONN + (integer) + + + + Turns on logging of connection activity when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_INIT + (integer) + + + + Turns on logging of initialization activity when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_OFF + (integer) + + + + Turns off logging of all subsystems when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_STMT + (integer) + + + + Turns on logging of statement activity when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SYSTEM_UTIL + (integer) + + + + Turns on logging of error function activity when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SEVERITY_ALL + (integer) + + + + Specifies that errors, warnings, and notices will be logged + when passed to sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SEVERITY_ERROR + (integer) + + + + Specifies that errors will be logged when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SEVERITY_NOTICE + (integer) + + + + Specifies that notices will be logged when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_LOG_SEVERITY_WARNING + (integer) + + + + Specifies that warnings will be logged when passed to + sqlsrv_configure as a parameter. + + + + + + SQLSRV_NULLABLE_YES + (integer) + + + + Indicates that a column is nullable. + + + + + + SQLSRV_NULLABLE_NO + (integer) + + + + Indicates that a column is not nullable. + + + + + + SQLSRV_NULLABLE_UNKNOWN + (integer) + + + + Indicates that it is not known if a column is nullable. + + + + + + SQLSRV_PARAM_IN + (integer) + + + + Indicates an input parameter when passed to sqlsrv_query + or sqlsrv_prepare. + + + + + + SQLSRV_PARAM_INOUT + (integer) + + + + Indicates a bidirectional parameter when passed to sqlsrv_query + or sqlsrv_prepare. + + + + + + SQLSRV_PARAM_OUT + (integer) + + + + Indicates an output parameter when passed to sqlsrv_query or + sqlsrv_prepare. + + + + + + SQLSRV_PHPTYPE_INT + (integer) + + + + Specifies an integer PHP data type. For usage information, see + How to: Specify PHP Types. + + + + + + SQLSRV_PHPTYPE_DATETIME + (integer) + + + + Specifies a datetime PHP data type. For usage information, see + How to: Specify PHP Types. + + + + + + SQLSRV_PHPTYPE_FLOAT + (integer) + + + + Specifies a float PHP data type. For usage information, see + How to: Specify PHP Types. + + + + + + SQLSRV_PHPTYPE_STREAM + (integer) + + + + Specifies a PHP stream. This constant works like a function and accepts an + encoding constant. See the SQLSRV_ENC_* constants. For usage information, see + How to: Specify PHP Types. + + + + + + SQLSRV_PHPTYPE_STRING + (integer) + + + + Specifies a string PHP data type. This constant works like a function and + accepts an encoding constant. See the SQLSRV_ENC_* constants. For usage information, + see How to: Specify PHP Types. + + + + + + SQLSRV_ENC_BINARY + (integer) + + + + Specifies that data is returned as a raw byte stream from the server without + performing encoding or translation. For usage information, see + How to: Specify PHP Types. + + + + + + SQLSRV_ENC_CHAR + (integer) + + + + Data is returned in 8-bit characters as specified in the code page of the + Windows locale that is set on the system. Any multi-byte characters or characters + that do not map into this code page are substituted with a single byte question + mark (?) character. This is the default encoding. For usage information, + see How to: Specify PHP Types. + + + + + + UTF-8 + (integer) + + + + Specifies that data is returned with UTF-8 encoding. For usage information, + see How to: Specify PHP Types. + + + + + + SQLSRV_SQLTYPE_BIGINT + (integer) + + + + Describes the bigint SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_BINARY + (integer) + + + + Describes the binary SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_BIT + (integer) + + + + Describes the bit SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_CHAR + (integer) + + + + Describes the char SQL Server data type. This constant works like a function + and accepts a parameter indicating the number characters. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_DATE + (integer) + + + + Describes the date SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_DATETIME + (integer) + + + + Describes the datetime SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_DATETIME2 + (integer) + + + + Describes the datetime2 SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_DATETIMEOFFSET + (integer) + + + + Describes the datetimeoffset SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_DECIMAL + (integer) + + + + Describes the decimal SQL Server data type. This constant works like a function + and accepts two parameters indicating (in order) precision and scale. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_FLOAT + (integer) + + + + Describes the float SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_IMAGE + (integer) + + + + Describes the image SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_INT + (integer) + + + + Describes the int SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_MONEY + (integer) + + + + Describes the money SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_NCHAR + (integer) + + + + Describes the nchar SQL Server data type. This constant works like a function + and accepts a single parameter indicating the character count. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_NUMERIC + (integer) + + + + Describes the numeric SQL Server data type. This constant works like a function + and accepts two parameter indicating (in order) precision and scale. For usage + information, see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_NVARCHAR + (integer) + + + + Describes the nvarchar SQL Server data type. This constant works like a function + and accepts a single parameter indicating the character count. For usage + information, see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_NVARCHAR('max') + (integer) + + + + Describes the nvarchar(MAX) SQL Server data type. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_NTEXT + (integer) + + + + Describes the ntext SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_REAL + (integer) + + + + Describes the real SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_SMALLDATETIME + (integer) + + + + Describes the smalldatetime SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_SMALLINT + (integer) + + + + Describes the smallint SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_SMALLMONEY + (integer) + + + + Describes the smallmoney SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_TEXT + (integer) + + + + Describes the text SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_TIME + (integer) + + + + Describes the time SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_TIMESTAMP + (integer) + + + + Describes the timestamp SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_TINYINT + (integer) + + + + Describes the tinyint SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_UNIQUEIDENTIFIER + (integer) + + + + Describes the uniqueidentifier SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_UDT + (integer) + + + + Describes the UDT SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_VARBINARY + (integer) + + + + Describes the varbinary SQL Server data type. This constant works like a function + and accepts a single parameter indicating the byte count. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_VARBINARY('max') + (integer) + + + + Describes the varbinary(MAX) SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_VARCHAR + (integer) + + + + Describes the varchar SQL Server data type. This constant works like a function + and accepts a single parameter indicating the character count. For usage information, + see How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_VARCHAR('max') + (integer) + + + + Describes the varchar(MAX) SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_SQLTYPE_XML + (integer) + + + + Describes the XML SQL Server data type. For usage information, see + How to: Specify SQL Types. + + + + + + SQLSRV_TXN_READ_UNCOMMITTED + (integer) + + + + Inidicates a transaction isolation level of READ UNCOMMITTED. This value is + used to set the TransactionIsolation level in the $connectionOptions arrary + passed to sqlsrv_connect. + + + + + + SQLSRV_TXN_READ_COMMITTED + (integer) + + + + Inidicates a transaction isolation level of READ COMMITTED. This value is + used to set the TransactionIsolation level in the $connectionOptions arrary + passed to sqlsrv_connect. + + + + + + SQLSRV_TXN_REPEATABLE_READ + (integer) + + + + Inidicates a transaction isolation level of REPEATABLE READ. This value is + used to set the TransactionIsolation level in the $connectionOptions arrary + passed to sqlsrv_connect. + + + + + + SQLSRV_TXN_SNAPSHOT + (integer) + + + + Inidicates a transaction isolation level of SNAPSHOT. This value is used to + set the TransactionIsolation level in the $connectionOptions arrary passed + to sqlsrv_connect. + + + + + + SQLSRV_TXN_READ_SERIALIZABLE + (integer) + + + + Inidicates a transaction isolation level of SERIALIZABLE. This value is used + to set the TransactionIsolation level in the $connectionOptions arrary passed + to sqlsrv_connect. + + + + + + SQLSRV_CURSOR_FORWARD + (integer) + + + + Inidicates a forward-only cursor. For usage information, see + How to: Specify a Cursor Type. + + + + + + SQLSRV_CURSOR_STATIC + (integer) + + + + Inidicates a static cursor. For usage information, see + How to: Specify a Cursor Type. + + + + + + SQLSRV_DYNAMIC + (integer) + + + + Inidicates a dynamic cursor. For usage information, see + How to: Specify a Cursor Type. + + + + + + SQLSRV_CURSOR_KEYSET + (integer) + + + + Inidicates a keyset cursor. For usage information, see + How to: Specify a Cursor Type. + + + + + + SQLSRV_SCROLL_NEXT + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + SQLSRV_SCROLL_PRIOR + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + SQLSRV_SCROLL_FIRST + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + SQLSRV_SCROLL_LAST + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + SQLSRV_SCROLL_ABSOLUTE + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + SQLSRV_SCROLL_RELATIVE + (integer) + + + + Specifies which row to select in a result set. For usage information, see + How to: Specify a Cursor Type and Select Rows. + + + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/entities.functions.xml b/reference/sqlsrv/entities.functions.xml new file mode 100644 index 0000000000..c117b6a4a1 --- /dev/null +++ b/reference/sqlsrv/entities.functions.xml @@ -0,0 +1,26 @@ +&reference.sqlsrv.functions.sqlsrv-begin-transaction; +&reference.sqlsrv.functions.sqlsrv-cancel; +&reference.sqlsrv.functions.sqlsrv-client-info; +&reference.sqlsrv.functions.sqlsrv-close; +&reference.sqlsrv.functions.sqlsrv-commit; +&reference.sqlsrv.functions.sqlsrv-configure; +&reference.sqlsrv.functions.sqlsrv-connect; +&reference.sqlsrv.functions.sqlsrv-errors; +&reference.sqlsrv.functions.sqlsrv-execute; +&reference.sqlsrv.functions.sqlsrv-fetch-array; +&reference.sqlsrv.functions.sqlsrv-fetch-object; +&reference.sqlsrv.functions.sqlsrv-fetch; +&reference.sqlsrv.functions.sqlsrv-field-metadata; +&reference.sqlsrv.functions.sqlsrv-free-stmt; +&reference.sqlsrv.functions.sqlsrv-get-config; +&reference.sqlsrv.functions.sqlsrv-get-field; +&reference.sqlsrv.functions.sqlsrv-has-rows; +&reference.sqlsrv.functions.sqlsrv-next-result; +&reference.sqlsrv.functions.sqlsrv-num-fields; +&reference.sqlsrv.functions.sqlsrv-num-rows; +&reference.sqlsrv.functions.sqlsrv-prepare; +&reference.sqlsrv.functions.sqlsrv-query; +&reference.sqlsrv.functions.sqlsrv-rollback; +&reference.sqlsrv.functions.sqlsrv-rows-affected; +&reference.sqlsrv.functions.sqlsrv-send-stream-data; +&reference.sqlsrv.functions.sqlsrv-server-info; diff --git a/reference/sqlsrv/functions/sqlsrv-begin-transaction.xml b/reference/sqlsrv/functions/sqlsrv-begin-transaction.xml new file mode 100644 index 0000000000..07503ef19c --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-begin-transaction.xml @@ -0,0 +1,136 @@ + + + + + sqlsrv_begin_transaction + Begins a database transaction + + + &reftitle.description; + + boolsqlsrv_begin_transaction + resourceconn + + + The transaction begun by sqlsrv_begin_transaction includes + all statements that were executed after the call to + sqlsrv_begin_transaction and before calls to + sqlsrv_rollback or sqlsrv_commit. + Explicit transactions should be started and committed or rolled back using + these functions instead of executing SQL statements that begin and committ/roll + back transactions. For more information, see + SQLSRV Transactions. + + + + &reftitle.parameters; + + + + conn + + + The connection resource returned by a call to sqlsrv_connect. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_begin_transaction</function> example + + The following example demonstrates how to use + sqlsrv_begin_transaction together with + sqlsrv_commit and sqlsrv_rollback. + + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Begin the transaction. */ +if ( sqlsrv_begin_transaction( $conn ) === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Initialize parameter values. */ +$orderId = 1; $qty = 10; $productId = 100; + +/* Set up and execute the first query. */ +$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID) + VALUES (?, ?, ?)"; +$params1 = array( $orderId, $qty, $productId ); +$stmt1 = sqlsrv_query( $conn, $sql1, $params1 ); + +/* Set up and execute the second query. */ +$sql2 = "UPDATE InventoryTable + SET Quantity = (Quantity - ?) + WHERE ProductID = ?"; +$params2 = array($qty, $productId); +$stmt2 = sqlsrv_query( $conn, $sql2, $params2 ); + +/* If both queries were successful, commit the transaction. */ +/* Otherwise, rollback the transaction. */ +if( $stmt1 && $stmt2 ) { + sqlsrv_commit( $conn ); + echo "Transaction committed.
"; +} else { + sqlsrv_rollback( $conn ); + echo "Transaction rolled back.
"; +} +?> +]]> +
+ &example.outputs.similar; +
+
+
+ + + &reftitle.seealso; + + + sqlsrv_commit + sqlsrv_rollback + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-cancel.xml b/reference/sqlsrv/functions/sqlsrv-cancel.xml new file mode 100644 index 0000000000..ef4a2dfda3 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-cancel.xml @@ -0,0 +1,137 @@ + + + + + sqlsrv_cancel + Cancels a statement + + + &reftitle.description; + + boolsqlsrv_cancel + resourcestmt + + + Cancels a statement. Any results associated with the statement that have not + been consumed are deleted. After sqlsrv_cancel has been + called, the specified statement can be re-executed if it was created with + sqlsrv_prepare. Calling sqlsrv_cancel + is not necessary if all the results associated with the statement have been + consumed. + + + + + &reftitle.parameters; + + + + stmt + + + The statement resource to be cancelled. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_cancel</function> example + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT Sales FROM Table_1"; + +$stmt = sqlsrv_prepare( $conn, $sql); + +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +if( sqlsrv_execute( $stmt ) === false) { + die( print_r( sqlsrv_errors(), true)); +} + +$salesTotal = 0; +$count = 0; + +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.
"; + +// Cancel the pending results. The statement can be reused. +sqlsrv_cancel( $stmt); +?> +]]> +
+
+
+
+ + + &reftitle.notes; + + The main difference between sqlsrv_cancel and + sqlsrv_free_stmt is that a statement resource cancelled with + sqlsrv_cancel can be re-executed if it was created with + sqlsrv_prepare. A statement resource cancelled with + sqlsrv_free_statement cannot be re-executed. + + + + + &reftitle.seealso; + + + sqlsrv_free_stmt + sqlsrv_prepare + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-client-info.xml b/reference/sqlsrv/functions/sqlsrv-client-info.xml new file mode 100644 index 0000000000..3b564d7943 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-client-info.xml @@ -0,0 +1,131 @@ + + + + + sqlsrv_client_info + Returns information about the client and specified connection + + + &reftitle.description; + + arraysqlsrv_client_info + resourceconn + + + Returns information about the client and specified connection + + + + + &reftitle.parameters; + + + + conn + + + The connection about which information is returned. + + + + + + + + + &reftitle.returnvalues; + + Returns an associative array with keys described in the table below. + Returns &false; otherwise. + + Array returned by sqlsrv_client_info + + + + Key + Description + + + + + DriverDllName + SQLNCLI10.DLL + + + DriverODBCVer + ODBC version (xx.yy) + + + DriverVer + SQL Server Native Client DLL version (10.5.xxx) + + + ExtensionVer + php_sqlsrv.dll version (2.0.xxx.x) + + + +
+
+
+ + + &reftitle.examples; + + + <function>sqlsrv_client_info</function> example + +"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connOptions ); + +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +if( $client_info = sqlsrv_client_info( $conn)) { + foreach( $client_info as $key => $value) { + echo $key.": ".$value."
"; + } +} else { + echo "Error in retrieving client info.
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_server_info + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-close.xml b/reference/sqlsrv/functions/sqlsrv-close.xml new file mode 100644 index 0000000000..1f8d9f1a81 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-close.xml @@ -0,0 +1,99 @@ + + + + + sqlsrv_close + Closes an open connection and releases resourses associated with the connection + + + &reftitle.description; + + boolsqlsrv_close + resourceconn + + + Closes an open connection and releases resourses associated with the connection. + + + + + &reftitle.parameters; + + + + conn + + + The connection to be closed. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_close</function> example + +"username", "PWD"=>"password", "Database"=>"dbname"); +$conn = sqlsrv_connect( $serverName, $connOptions ); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +//------------------------------------- +// Perform database operations here. +//------------------------------------- + +// Close the connection. +sqlsrv_close( $conn ); +?> +]]> + + + + + + + &reftitle.seealso; + + + sqlsrv_connect + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-commit.xml b/reference/sqlsrv/functions/sqlsrv-commit.xml new file mode 100644 index 0000000000..1e9ffccace --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-commit.xml @@ -0,0 +1,136 @@ + + + + + sqlsrv_commit + Commits a transaction that was begun with sqlsrv_begin_transaction + + + &reftitle.description; + + boolsqlsrv_commit + resourceconn + + + Commits a transaction that was begun with sqlsrv_begin_transaction. + The connection is returned to auto-commit mode after sqlsrv_commit + is called. The transaction that is committed includes all statements that were + executed after the call to sqlsrv_begin_transaction. + Explicit transactions should be started and committed or rolled back using these + functions instead of executing SQL statements that begin and committ/roll back + transactions. For more information, see + SQLSRV Transactions. + + + + + &reftitle.parameters; + + + + conn + + + The connection on which the transaction is to be committed. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_commit</function> example + + The following example demonstrates how to use sqlsrv_commit + together with sqlsrv_begin_transaction and + sqlsrv_rollback. + + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Begin the transaction. */ +if ( sqlsrv_begin_transaction( $conn ) === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Initialize parameter values. */ +$orderId = 1; $qty = 10; $productId = 100; + +/* Set up and execute the first query. */ +$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID) + VALUES (?, ?, ?)"; +$params1 = array( $orderId, $qty, $productId ); +$stmt1 = sqlsrv_query( $conn, $sql1, $params1 ); + +/* Set up and execute the second query. */ +$sql2 = "UPDATE InventoryTable + SET Quantity = (Quantity - ?) + WHERE ProductID = ?"; +$params2 = array($qty, $productId); +$stmt2 = sqlsrv_query( $conn, $sql2, $params2 ); + +/* If both queries were successful, commit the transaction. */ +/* Otherwise, rollback the transaction. */ +if( $stmt1 && $stmt2 ) { + sqlsrv_commit( $conn ); + echo "Transaction committed.
"; +} else { + sqlsrv_rollback( $conn ); + echo "Transaction rolled back.
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_begin_transaction + sqlsrv_rollback + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-configure.xml b/reference/sqlsrv/functions/sqlsrv-configure.xml new file mode 100644 index 0000000000..5fcaad5299 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-configure.xml @@ -0,0 +1,115 @@ + + + + + sqlsrv_configure + Changes the driver error handling and logging configurations + + + &reftitle.description; + + boolsqlsrv_configure + stringsetting + mixedvalue + + + Changes the driver error handling and logging configurations. + + + + + &reftitle.parameters; + + + + setting + + + The name of the setting to set. The possible values are + "WarningsReturnAsErrors", "LogSubsystems", and "LogSeverity". + + + + + value + + + The value of the specified setting. The following table shows possible values: + + Error and Logging Setting Options + + + + Setting + Options + + + + + WarningsReturnAsErrors + 1 (&true;) or 0 (&false;) + + + LogSubsystems + SQLSRV_LOG_SYSTEM_ALL (-1) + SQLSRV_LOG_SYSTEM_CONN (2) + SQLSRV_LOG_SYSTEM_INIT (1) + SQLSRV_LOG_SYSTEM_OFF (0) + SQLSRV_LOG_SYSTEM_STMT (4) + SQLSRV_LOG_SYSTEM_UTIL (8) + + + LogSeverity + SQLSRV_LOG_SEVERITY_ALL (-1) + SQLSRV_LOG_SEVERITY_ERROR (1) + SQLSRV_LOG_SEVERITY_NOTICE (4) + SQLSRV_LOG_SEVERITY_WARNING (2) + + + +
+
+
+
+
+
+
+ + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.seealso; + + + SQLSRV Error Handling. + Logging SQLSRV Activity. + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-connect.xml b/reference/sqlsrv/functions/sqlsrv-connect.xml new file mode 100644 index 0000000000..ce7c7530e7 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-connect.xml @@ -0,0 +1,177 @@ + + + + + sqlsrv_connect + Opens a connection to a Microsoft SQL Server database + + + &reftitle.description; + + resourcesqlsrv_connect + stringserverName + arrayconnectionInfo + + + Opens a connection to a Microsoft SQL Server database. By default, the connection + is attempted using Windows Authentication. To connect using SQL Server + Authentication, include "UID" and "PWD" in the connection options array. + + + + + &reftitle.parameters; + + + + serverName + + + The name of the server to which a connection is established. To connect + to a specific instance, follow the server name with a forward slash + and the instance name (e.g. serverName\sqlexpress). + + + + + connectionInfo + + + An associative array that specifies options for connecting to the server. + If values for the UID and PWD keys are not specified, the connection + will be attempted using Windows Authentication. For a complete list of supported + keys, see SQLSRV Connection Options. + + + + + + + + + &reftitle.returnvalues; + + A connection resource. If a connection cannot be successfully opened, &false; is returned. + + + + + &reftitle.examples; + + + Connect using Windows Authentication. + +"dbName"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); + +if( $conn ) { + echo "Connection established.
"; +}else{ + echo "Connection could not be established.
"; + die( print_r( sqlsrv_errors(), true)); +} +?> +]]> +
+
+
+ + + Connect by specifying a user name and password. + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); + +if( $conn ) { + echo "Connection established.
"; +}else{ + echo "Connection could not be established.
"; + die( print_r( sqlsrv_errors(), true)); +} +?> +]]> +
+
+
+ + + Connect on a specifed port. + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); + +if( $conn ) { + echo "Connection established.
"; +}else{ + echo "Connection could not be established.
"; + die( print_r( sqlsrv_errors(), true)); +} +?> +]]> +
+
+
+
+ + + &reftitle.notes; + + By default, the sqlsrv_connect uses connection pooling to + improve connection performance. To turn off connection pooling (i.e. force a + new connection on each call), set the "ConnectionPooling" option in the + $connectionOptions array to 0 (or &false;). For more information, see + SQLSRV Connection Pooling. + + + The SQLSRV extension does not have a dedicated function for changing which + database is connected to. The target database is specified in the + $connectionOptions array that is passed to sqlsrv_connect. To change the + database on an open connection, execute the following query "USE dbName" + (e.g. sqlsrv_query($conn, "USE dbName")). + + + + + &reftitle.seealso; + + + sqlsrv_close + sqlsrv_errors + sqlsrv_query + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-errors.xml b/reference/sqlsrv/functions/sqlsrv-errors.xml new file mode 100644 index 0000000000..579dbf3052 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-errors.xml @@ -0,0 +1,159 @@ + + + + + sqlsrv_errors + Returns error and warning information about the last SQLSRV operation performed + + + &reftitle.description; + + + mixedsqlsrv_errors + interrorsOrWarnings + + + Returns error and warning information about the last SQLSRV operation performed. + + + + + &reftitle.parameters; + + + + errorsOrWarnings + + + Determines whether error information, warning information, or both are + returned. If this parameter is not supplied, both error information and + warning information are returned. The following are the supported values + for this parameter: SQLSRV_ERR_ALL, SQLSRV_ERR_ERRORS, SQLSRV_ERR_WARNINGS. + + + + + + + + + &reftitle.returnvalues; + + If errors and/or warnings occured on the last sqlsrv operation, and array of + arrays containing error information is returned. If no errors and/or warnings + occured on the last sqlsrv operation, &null; is returned. The following table + describes the structure of the returned arrays: + + Array returned by sqlsrv_errors + + + + Key + Description + + + + + SQLSTATE + For errors that originate from the ODBC driver, the SQLSTATE returned + by ODBC. For errors that originate from the Microsoft Drivers for PHP for + SQL Server, a SQLSTATE of IMSSP. For warnings that originate from the + Microsoft Drivers for PHP for SQL Server, a SQLSTATE of 01SSP. + + + + code + For errors that originate from SQL Server, the native SQL Server + error code. For errors that originate from the ODBC driver, the error + code returned by ODBC. For errors that originate from the Microsoft Drivers + for PHP for SQL Server, the Microsoft Drivers for PHP for SQL Server error code. + + + + message + A description of the error. + + + +
+
+
+ + + &reftitle.examples; + + + <function>functionname</function> example + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +/* Set up a query to select an invalid column name. */ +$sql = "SELECT BadColumnName FROM Table_1"; + +/* Execution of the query will fail because of the bad column name. */ +$stmt = sqlsrv_query( $conn, $sql ); +if( $stmt === false ) { + if( ($errors = sqlsrv_errors() ) != null) { + foreach( $errors as $error ) { + echo "SQLSTATE: ".$error[ 'SQLSTATE']."
"; + echo "code: ".$error[ 'code']."
"; + echo "message: ".$error[ 'message']."
"; + } + } +} +?> +]]> +
+
+
+
+ + + &reftitle.notes; + + By default, warnings generated on a call to any SQLSRV function are treated + as errors. This means that if a warning occurs on a call to a SQLSRV function, + the function returns &false;. However, warnings that correspond to SQLSTATE + values 01000, 01001, 01003, and 01S02 are never treated as errors. For + information about changing this behavior, see sqlsrv_configure + and the WarningsReturnAsErrors setting. + + + + + &reftitle.seealso; + + + sqlsrv_configure + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-execute.xml b/reference/sqlsrv/functions/sqlsrv-execute.xml new file mode 100644 index 0000000000..82ce17a60d --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-execute.xml @@ -0,0 +1,136 @@ + + + + + sqlsrv_execute + Executes a statement prepared with sqlsrv_prepare + + + &reftitle.description; + + boolsqlsrv_execute + resourcestmt + + + Executes a statement prepared with sqlsrv_prepare. This + function is ideal for executing a prepared statement multiple times with + different parameter values. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource returned by sqlsrv_prepare. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_execute</function> example + + This example demonstrates how to prepare a statement with + sqlsrv_prepare and re-execute it multiple times (with + different parameter values) using sqlsrv_execute. + + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "UPDATE Table_1 + SET OrderQty = ? + WHERE SalesOrderID = ?"; + +// Initialize parameters and prepare the statement. +// Variables $qty and $id are bound to the statement, $stmt. +$qty = 0; $id = 0; +$stmt = sqlsrv_prepare( $conn, $sql, array( &$qty, &$id)); +if( !$stmt ) { + die( print_r( sqlsrv_errors(), true)); +} + +// Set up the SalesOrderDetailID and OrderQty information. +// This array maps the order ID to order quantity in key=>value pairs. +$orders = array( 1=>10, 2=>20, 3=>30); + +// Execute the statement for each order. +foreach( $orders as $id => $qty) { + // Because $id and $qty are bound to $stmt1, their updated + // values are used with each execution of the statement. + if( sqlsrv_execute( $stmt ) === false ) { + die( print_r( sqlsrv_errors(), true)); + } +} +?> +]]> + + + + + + + &reftitle.notes; + + When you prepare a statement that uses variables as parameters, the variables + are bound to the statement. This means that if you update the values of the + variables, the next time you execute the statement it will run with updated + parameter values. For statements that you plan to execute only once, use + sqlsrv_query. + + + + + &reftitle.seealso; + + + sqlsrv_prepare + sqlsrv_query + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-fetch-array.xml b/reference/sqlsrv/functions/sqlsrv-fetch-array.xml new file mode 100644 index 0000000000..8ef200a7b2 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-fetch-array.xml @@ -0,0 +1,186 @@ + + + + + sqlsrv_fetch_array + Returns a row as an array + + + &reftitle.description; + + arraysqlsrv_fetch_array + resourcestmt + intfetchType + introw + intoffset + + + Returns the next available row of data as an associative array, a numeric + array, or both (the default). + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource returned by sqlsrv_query or sqlsrv_execute. + + + + + fetchType + + + A predefined constant specifying the type of array to return. Possible + values are SQLSRV_FETCH_ASSOC, + SQLSRV_FETCH_NUMERIC, and + SQLSRV_FETCH_BOTH (the default). + + + A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a + result set with multiple columns of the same name. + + + + + row + + + Specifies the row to access in a result set that uses a scrollable cursor. + Possible values are SQLSRV_SCROLL_NEXT, + SQLSRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST, + SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and, + SQLSRV_SCROLL_RELATIVE (the default). When this parameter + is specified, the fetchType must be explicitly defined. + + + + + + + + + &reftitle.returnvalues; + + Returns an array on success, &null; if there are no more rows to return, and + &false; if an error occurs. + + + + + &reftitle.examples; + + + Retrieving an associative array. + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo ); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT FirstName, LastName FROM SomeTable"; +$stmt = sqlsrv_query( $conn, $sql ); +if( $stmt === false) { + die( print_r( sqlsrv_errors(), true) ); +} + +while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { + echo $row['LastName'].", ".$row['FirstName']."
"; +} + +sqlsrv_free_stmt( $stmt); +?> +]]> +
+
+
+ + + Retrieving a numeric array. + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo ); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT FirstName, LastName FROM SomeTable"; +$stmt = sqlsrv_query( $conn, $sql ); +if( $stmt === false) { + die( print_r( sqlsrv_errors(), true) ); +} + +while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) { + echo $row[0].", ".$row[1]."
"; +} + +sqlsrv_free_stmt( $stmt); +?> +]]> +
+
+
+
+ + + &reftitle.notes; + + Not specifying the fetchType or explicity using the + SQLSRV_FETCH_TYPE constant in the examples above will + return an array that has both associative and numeric keys. + + + If more than one column is returned with the same name, the last column will + take precedence. To avoid field name collisions, use aliases. + + + If a column with no name is returned, the associative key for the array element + will be an empty string (""). + + + + + &reftitle.seealso; + + + sqlsrv_connect + sqlsrv_query + sqlsrv_errors + sqlsrv_fetch + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-fetch-object.xml b/reference/sqlsrv/functions/sqlsrv-fetch-object.xml new file mode 100644 index 0000000000..92232a3609 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-fetch-object.xml @@ -0,0 +1,190 @@ + + + + + sqlsrv_fetch_object + Retrieves the next row of data in a result set as an object + + + &reftitle.description; + + mixedsqlsrv_fetch_object + resourcestmt + stringclassName + arrayctorParams + introw + intoffset + + + Retrieves the next row of data in a result set as an instance of the specified + class with properties that match the row field names and values that correspond + to the row field values. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource created by sqlsrv_query or + sqlsrv_execute. + + + + + className + + + The name of the class to instantiate. If no class name is specified, + stdClass is instantiated. + + + + + ctorParams + + + Values passed to the constructor of the specified class. If the constructor + of the specified class takes parameters, the ctorParams array must be + supplied. + + + + + row + + + The row to be accessed. This parameter can only be used if the specified + statement was prepared with a scrollable cursor. In that case, this parameter + can take on one of the following values: + + SQLSRV_SCROLL_NEXT + SQLSRV_SCROLL_PRIOR + SQLSRV_SCROLL_FIRST + SQLSRV_SCROLL_LAST + SQLSRV_SCROLL_ABSOLUTE + SQLSRV_SCROLL_RELATIVE + + + + + + offset + + + Specifies the row to be accessed if the row parameter is set to + SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row + in a result set has index 0. + + + + + + + + + &reftitle.returnvalues; + + Returns an object on success, &null; if there are no more rows to return, + and &false; if an error occurs or if the specified class does not exist. + + + + + &reftitle.examples; + + + <function>sqlsrv_fetch_object</function> example + + The following example demonstrates how to retrieve a row as a stdClass object. + + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT fName, lName FROM Table_1"; +$stmt = sqlsrv_query( $conn, $sql); +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +// Retrieve each row as an object. +// Because no class is specified, each row will be retrieved as a stdClass object. +// Property names correspond to field names. +while( $obj = sqlsrv_fetch_object( $stmt)) { + echo $obj->fName.", ".$obj->lName."
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.notes; + + If a class name is specified with the optional $className parameter and the + class has properties whose names match the result set field names, the corresponding + result set values are applied to the properties. If a result set field name + does not match a class property, a property with the result set field name is added + to the object and the result set value is applied to the property. The following + rules apply when using the $className parameter: + + Field-property name matching is case-sensitive. + Field-property matching occurs regardless of access modifiers. + Class property data types are ignored when applying a field value to a property. + If the class does not exist, the function returns &false; and adds an error to the error collection. + + Regardless of whether the $className parameter is supplied, if a field with no + name is returned, the field value will be ignored and a warning will be added + to the error collection. + + + When consuming a result set that has multiple columns with the same name, it may + be better to use sqlsrv_fetch_array or the combination of + sqlsrv_fetch and sqlsrv_get_field. + + + + + &reftitle.seealso; + + + sqlsrv_fetch + sqlsrv_fetch_array + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-fetch.xml b/reference/sqlsrv/functions/sqlsrv-fetch.xml new file mode 100644 index 0000000000..709dbe3efd --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-fetch.xml @@ -0,0 +1,155 @@ + + + + + sqlsrv_fetch + Makes the next row in a result set available for reading + + + &reftitle.description; + + + mixedsqlsrv_fetch + resourcestmt + introw + intoffset + + + Makes the next row in a result set available for reading. Use + sqlsrv_get_field to read the fields of the row. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource created by executing sqlsrv_query + or sqlsrv_execute. + + + + + row + + + The row to be accessed. This parameter can only be used if the specified + statement was prepared with a scrollable cursor. In that case, this parameter + can take on one of the following values: + + SQLSRV_SCROLL_NEXT + SQLSRV_SCROLL_PRIOR + SQLSRV_SCROLL_FIRST + SQLSRV_SCROLL_LAST + SQLSRV_SCROLL_ABSOLUTE + SQLSRV_SCROLL_RELATIVE + + + + + + offset + + + Specifies the row to be accessed if the row parameter is set to + SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first + row in a result set has index 0. + + + + + + + + + &reftitle.returnvalues; + + Returns &true; if the next row of a result set was successfully retrieved, + &false; if an error occurs, and &null; if there are no more rows in the result set. + + + + + &reftitle.examples; + + + <function>sqlsrv_fetch</function> example + + The following example demonstrates how to retrieve a row with + sqlsrv_fetch and get the row fields with + sqlsrv_get_field. + + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT Name, Comment + FROM Table_1 + WHERE ReviewID=1"; +$stmt = sqlsrv_query( $conn, $sql); +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +// Make the first (and in this case, only) row of the result set available for reading. +if( sqlsrv_fetch( $stmt ) === false) { + die( print_r( sqlsrv_errors(), true)); +} + +// Get the row fields. Field indeces start at 0 and must be retrieved in order. +// Retrieving row fields by name is not supported by sqlsrv_get_field. +$name = sqlsrv_get_field( $stmt, 0); +echo "$name: "; + +$comment = sqlsrv_get_field( $stmt, 1); +echo $comment; +?> +]]> + + + + + + + + &reftitle.seealso; + + + sqlsrv_get_field + sqlsrv_fetch_array + sqlsrv_fetch_object + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-field-metadata.xml b/reference/sqlsrv/functions/sqlsrv-field-metadata.xml new file mode 100644 index 0000000000..1f0f8104e5 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-field-metadata.xml @@ -0,0 +1,149 @@ + + + + + sqlsrv_field_metadata + Retrieves metadata for the fields of a statement prepared by + sqlsrv_prepare or sqlsrv_query + + + + &reftitle.description; + + mixedsqlsrv_field_metadata + resourcestmt + + + Retrieves metadata for the fields of a statement prepared by + sqlsrv_prepare or sqlsrv_query. + sqlsrv_field_metadata can be called on a statement before + or after statement execution. + + + + + &reftitle.parameters; + + + + stmt + + + The statment resource for which metadata is returned. + + + + + + + + + &reftitle.returnvalues; + + Returns an array of arrays is returned on success. Otherwise, &false; is returned. + Each returned array is described by the following table: + + Array returned by sqlsrv_field_metadata + + + + Key + Description + + + + + Name + The name of the field. + + + Type + The numeric value for the SQL type. + + + Size + The number of characters for fields of character type, the number of + bytes for fields of binary type, or &null; for other types. + + + Precision + The precision for types of variable precision, &null; for other types. + + + Scale + The scale for types of variable scale, &null; for other types. + + + Nullable + An enumeration indicating whether the column is nullable, not nullable, + or if it is not known. + + + +
+ For more information, see sqlsrv_field_metadata + in the Microsoft SQLSRV documentation. +
+
+ + + &reftitle.examples; + + + <function>sqlsrv_field_metadata</function> example + +"AdventureWorks", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT * FROM Table_1"; +$stmt = sqlsrv_prepare( $conn, $sql ); + +foreach( sqlsrv_field_metadata( $stmt ) as $fieldMetadata ) { + foreach( $fieldMetadata as $name => $value) { + echo "$name: $value
"; + } + echo "
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_client_info + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-free-stmt.xml b/reference/sqlsrv/functions/sqlsrv-free-stmt.xml new file mode 100644 index 0000000000..c41a8e1796 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-free-stmt.xml @@ -0,0 +1,121 @@ + + + + + sqlsrv_free_stmt + Frees all resources for the specified statement + + + &reftitle.description; + + boolsqlsrv_free_stmt + resourcestmt + + + Frees all resources for the specified statement. The statement cannot be used + after sqlsrv_free_stmt has been called on it. If + sqlsrv_free_stmt is called on an in-progress statement + that alters server state, statement execution is terminated and the statement + is rolled back. + + + + + &reftitle.parameters; + + + + stmt + + + The statment for which resources are freed. + Note that &null; is a valid parameter value. This allows the function to be + called multiple times in a script. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_free_stmt</function> example + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$stmt = sqlsrv_query( $conn, "SELECT * FROM Table_1"); +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +/*------------------------------- + Process query results here. +-------------------------------*/ + +/* Free the statement resources. */ +sqlsrv_free_stmt( $stmt); + +?> +]]> + + + + + + + &reftitle.notes; + + The main difference between sqlsrv_free_stmt and + sqlsrv_cancel is that a statement resource cancelled with + sqlsrv_cancel can be re-executed if it was created with + sqlsrv_prepare. A statement resource cancelled with + sqlsrv_free_statement cannot be re-executed. + + + + &reftitle.seealso; + + + sqlsrv_cancel + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-get-config.xml b/reference/sqlsrv/functions/sqlsrv-get-config.xml new file mode 100644 index 0000000000..7cbfeecf3a --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-get-config.xml @@ -0,0 +1,73 @@ + + + + + sqlsrv_get_config + Returns the value of the specified configuration setting + + + &reftitle.description; + + mixedsqlsrv_get_config + stringsetting + + + Returns the value of the specified configuration setting. + + + + + &reftitle.parameters; + + + + setting + + + The name of the setting for which the value is returned. For a list of + configurable settings, see sqlsrv_configure. + + + + + + + + + &reftitle.returnvalues; + + Returns the value of the specified setting. If an invalid setting is specified, + &false; is returned. + + + + + &reftitle.seealso; + + + sqlsrv_configure + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-get-field.xml b/reference/sqlsrv/functions/sqlsrv-get-field.xml new file mode 100644 index 0000000000..d92b5acf1d --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-get-field.xml @@ -0,0 +1,146 @@ + + + + + sqlsrv_get_field + Gets field data from the currently selected row + + + &reftitle.description; + + mixedsqlsrv_get_field + resourcestmt + intfieldIndex + intgetAsType + + + Gets field data from the currently selected row. Fields must be accessed in + order. Field indices start at 0. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource returned by sqlsrv_query or + sqlsrv_execute. + + + + + fieldIndex + + + The index of the field to be retrieved. Field indices start at 0. Fields + must be accessed in order. i.e. If you access field index 1, then field + index 0 will not be available. + + + + + getAsType + + + The PHP data type for the returned field data. If this parameter is not + set, the field data will be returned as its default PHP data type. + For information about default PHP data types, see + Default PHP Data Types + in the Microsoft SQLSRV documentation. + + + + + + + + + &reftitle.returnvalues; + + Returns data from the specified field on success. Returns &false; otherwise. + + + + + &reftitle.examples; + + + <function>sqlsrv_get_field</function> example + + The following example demonstrates how to retrieve a row with + sqlsrv_fetch and get the row fields with + sqlsrv_get_field. + + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT Name, Comment + FROM Table_1 + WHERE ReviewID=1"; +$stmt = sqlsrv_query( $conn, $sql); +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +// Make the first (and in this case, only) row of the result set available for reading. +if( sqlsrv_fetch( $stmt ) === false) { + die( print_r( sqlsrv_errors(), true)); +} + +// Get the row fields. Field indeces start at 0 and must be retrieved in order. +// Retrieving row fields by name is not supported by sqlsrv_get_field. +$name = sqlsrv_get_field( $stmt, 0); +echo "$name: "; + +$comment = sqlsrv_get_field( $stmt, 1); +echo $comment; +?> +]]> + + + + + + + &reftitle.seealso; + + + sqlsrv_fetch + sqlsrv_fetch_array + sqlsrv_fetch_object + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-has-rows.xml b/reference/sqlsrv/functions/sqlsrv-has-rows.xml new file mode 100644 index 0000000000..e4ab6eb716 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-has-rows.xml @@ -0,0 +1,102 @@ + + + + + sqlsrv_has_rows + Indicates whether the specified statement has rows + + + &reftitle.description; + + boolsqlsrv_has_rows + resourcestmt + + + Indicates whether the specified statement has rows. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource returned by sqlsrv_query or + sqlsrv_execute. + + + + + + + + + &reftitle.returnvalues; + + Returns &true; if the specified statement has rows and &false; if the statement + does not have rows or if an error occured. + + + + + &reftitle.examples; + + + <function>sqlsrv_has_rows</function> example + +"dbName", "UID"=>"username", "PWD"=>"password" ) +$conn = sqlsrv_connect( $server, $connectionInfo ); + +$stmt = sqlsrv_query( $conn, "SELECT * FROM Table_1"); + +if ($stmt) { + $rows = sqlsrv_has_rows( $stmt ); + if ($rows === true) + echo "There are rows.
"; + else + echo "There are no rows.
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_num_rows + sqlsrv_query + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-next-result.xml b/reference/sqlsrv/functions/sqlsrv-next-result.xml new file mode 100644 index 0000000000..9a660a781f --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-next-result.xml @@ -0,0 +1,120 @@ + + + + + sqlsrv_next_result + Makes the next result of the specified statement active + + + &reftitle.description; + + mixedsqlsrv_next_result + + resourcestmt + + + Makes the next result of the specified statement active. Results include result + sets, row counts, and output parameters. + + + + + &reftitle.parameters; + + + + stmt + + + The statment on which the next result is being called. + + + + + + + + + &reftitle.returnvalues; + + Returns &true; if the next result was successfully retrieved, &false; if an error + occurred, and &null; if there are no more results to retrieve. + + + + + &reftitle.examples; + + + <function>sqlsrv_next_result</function> example + + The following example executes a batch query that inserts into a table and + then selects from the table. This produces two results on the statement: + one for the rows affected by the INSERT and one for the rows returned by + the SELECT. To get to the rows returned by the SELECT, + sqlsrv_next_result must be called to move past the first result. + + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); + +$query = "INSERT INTO Table_1 (id, data) VALUES (?,?); SELECT * FROM TABLE_1;"; +$params = array(1, "some data"); +$stmt = sqlsrv_query($conn, $query, $params); + +// Consume the first result (rows affected by INSERT) without calling sqlsrv_next_result. +echo "Rows affected: ".sqlsrv_rows_affected($stmt)."
"; + +// Move to the next result and display results. +$next_result = sqlsrv_next_result($stmt); +if( $next_result ) { + while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)){ + echo $row['id'].": ".$row['data']."
"; + } +} elseif( is_null($next_result)) { + echo "No more results.
"; +} else { + die(print_r(sqlsrv_errors(), true)); +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_query + sqlsrv_fetch_array + sqlsrv_rows_affected + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-num-fields.xml b/reference/sqlsrv/functions/sqlsrv-num-fields.xml new file mode 100644 index 0000000000..61da65bc22 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-num-fields.xml @@ -0,0 +1,113 @@ + + + + + sqlsrv_num_fields + Retrieves the number of fields (columns) on a statement + + + &reftitle.description; + + mixedsqlsrv_num_fields + resourcestmt + + + Retrieves the number of fields (columns) on a statement. + + + + + &reftitle.parameters; + + + + stmt + + + The statment for which the number of fields is returned. + sqlsrv_num_fields can be called on a statement before + or after statement execution. + + + + + + + + + &reftitle.returnvalues; + + Returns the number of fields on success. Returns &false; otherwise. + + + + + &reftitle.examples; + + + <function>sqlsrv_num_fields</function> example + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "SELECT * FROM Table_1"; +$stmt = sqlsrv_query($conn, $sql); +if( $stmt === false) { + die( print_r( sqlsrv_errors(), true)); +} + +$numFields = sqlsrv_num_fields( $stmt ); + +while( sqlsrv_fetch( $stmt )) { + // Iterate through the fields of each row. + for($i = 0; $i < $numFields; $i++) { + { + echo sqlsrv_get_field($stmt, $i)." "; + } + echo "
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_field_metadata + sqlsrv_fetch + sqlsrv_get_field + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-num-rows.xml b/reference/sqlsrv/functions/sqlsrv-num-rows.xml new file mode 100644 index 0000000000..fa96aa2959 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-num-rows.xml @@ -0,0 +1,111 @@ + + + + + sqlsrv_num_rows + Retrieves the number of rows in a result set + + + &reftitle.description; + + mixedsqlsrv_num_rows + resourcestmt + + + Retrieves the number of rows in a result set. This function requires that the + statment resource be created with a static or keyset cursor. For more information, + see sqlsrv_query, sqlsrv_prepare, + or Specifying a Cursor Type and Selecting Rows + in the Microsoft SQLSRV documentation. + + + + + &reftitle.parameters; + + + + stmt + + + The statement for which the row count is returned. The statment resource + must be created with a static or keyset cursor. For more information, see + sqlsrv_query, sqlsrv_prepare, or + Specifying a Cursor Type and Selecting Rows + in the Microsoft SQLSRV documentation. + + + + + + + + + &reftitle.returnvalues; + + Returns the number of rows retrieved on success and &false; if an error occured. + If a forward cursor (the default) or dynamic cursor is used, &false; is returned. + + + + + &reftitle.examples; + + + <function>sqlsrv_num_rows</function> example + +"dbName", "UID"=>"username", "PWD"=>"password" ); +$conn = sqlsrv_connect( $server, $connectionInfo ); + +$sql = "SELECT * FROM Table_1"; +$params = array(); +$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); +$stmt = sqlsrv_query( $conn, $sql , $params, $options ); + +$row_count = sqlsrv_num_rows( $stmt ); + +if ($row_count === false) + echo "Error in retrieveing row count."; +else + echo $row_count; +?> +]]> + + + + + + + &reftitle.seealso; + + + sqlsrv_has_rows + sqlsrv_rows_affected + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-prepare.xml b/reference/sqlsrv/functions/sqlsrv-prepare.xml new file mode 100644 index 0000000000..9abc5e4fb5 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-prepare.xml @@ -0,0 +1,237 @@ + + + + + sqlsrv_prepare + Prepares a query for execution + + + &reftitle.description; + + mixedsqlsrv_prepare + resourceconn + stringsql + arrayparams + arrayoptions + + + Prepares a query for execution. This function is ideal for preparing a query + that will be executed multiple times with different parameter values. + + + + + &reftitle.parameters; + + + + conn + + + A connection resource returned by sqlsrv_connect. + + + + + sql + + + The string that defines the query to be prepared and executed. + + + + + params + + + An array specifying parameter information when executing a parameterized + query. Array elements can be any of the following: + + A literal value + A PHP variable + An array with this structure: + array($value [, $direction [, $phpType [, $sqlType]]]) + + The following table describes the elements in the array structure above: + + + Array structure + + + + Element + Description + + + + + $value + A literal value, a PHP variable, or a PHP by-reference variable. + + + $direction (optional) + One of the following SQLSRV constants used to indicate the + parameter direction: SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, SQLSRV_PARAM_INOUT. + The default value is SQLSRV_PARAM_IN. + + + $phpType (optional) + A SQLSRV_PHPTYPE_* constant that specifies PHP data type of the + returned value. + + + $sqlType (optional) + A SQLSRV_SQLTYPE_* constant that specifies the SQL Server data + type of the input value. + + + +
+
+
+ + options + + + An array specifing query property options. The supported keys are described + in the following table: + + + Query Options + + + + Key + Values + Description + + + + + QueryTimeout + A positive integer value. + Sets the query timeout in seconds. By default, the driver will + wait indefinitely for results. + + + SendStreamParamsAtExec + &true; or &false; (the default is &true;) + Configures the driver to send all stream data at execution (&true), + or to send stream data in chunks (&false;). By default, the value is set to &true;. + For more information, see sqlsrv_send_stream_data. + + + Scrollable + SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_STATIC, SQLSRV_CURSOR_DYNAMIC, + or SQLSRV_CURSOR_KEYSET + See Specifying a Cursor Type and Selecting Rows + in the Microsoft SQLSRV documentation. + + + +
+
+
+
+
+
+ + + &reftitle.returnvalues; + + Returns a statement resource on success and &false; if an error occurred. + + + + + &reftitle.examples; + + + <function>sqlsrv_prepare</function> example + + This example demonstrates how to prepare a statement with sqlsrv_prepare + and re-execute it multiple times (with different parameter values) using sqlsrv_execute. + + +"dbName", "UID"=>"username", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "UPDATE Table_1 + SET OrderQty = ? + WHERE SalesOrderID = ?"; + +// Initialize parameters and prepare the statement. +// Variables $qty and $id are bound to the statement, $stmt. +$qty = 0; $id = 0; +$stmt = sqlsrv_prepare( $conn, $sql, array( &$qty, &$id)); +if( !$stmt ) { + die( print_r( sqlsrv_errors(), true)); +} + +// Set up the SalesOrderDetailID and OrderQty information. +// This array maps the order ID to order quantity in key=>value pairs. +$orders = array( 1=>10, 2=>20, 3=>30); + +// Execute the statement for each order. +foreach( $orders as $id => $qty) { + // Because $id and $qty are bound to $stmt1, their updated + // values are used with each execution of the statement. + if( sqlsrv_execute( $stmt ) === false ) { + die( print_r( sqlsrv_errors(), true)); + } +} +?> +]]> + + + + + + + &reftitle.notes; + + When you prepare a statement that uses variables as parameters, the variables + are bound to the statement. This means that if you update the values of the + variables, the next time you execute the statement it will run with updated + parameter values. For statements that you plan to execute only once, use + sqlsrv_query. + + + + + &reftitle.seealso; + + + sqlsrv_execute + sqlsrv_query + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-query.xml b/reference/sqlsrv/functions/sqlsrv-query.xml new file mode 100644 index 0000000000..2521e7d015 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-query.xml @@ -0,0 +1,213 @@ + + + + + sqlsrv_query + Prepares and executes a query. + + + &reftitle.description; + + mixedsqlsrv_query + resourceconn + stringsql + arrayparams + arrayoptions + + + Prepares and executes a query. + + + + + &reftitle.parameters; + + + + conn + + + A connection resource returned by sqlsrv_connect. + + + + + sql + + + The string that defines the query to be prepared and executed. + + + + + params + + + An array specifying parameter information when executing a parameterized query. + Array elements can be any of the following: + + A literal value + A PHP variable + An array with this structure: + array($value [, $direction [, $phpType [, $sqlType]]]) + + The following table describes the elements in the array structure above: + + + Array structure + + + + Element + Description + + + + + $value + A literal value, a PHP variable, or a PHP by-reference variable. + + + $direction (optional) + One of the following SQLSRV constants used to indicate the + parameter direction: SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, SQLSRV_PARAM_INOUT. + The default value is SQLSRV_PARAM_IN. + + + $phpType (optional) + A SQLSRV_PHPTYPE_* constant that specifies PHP data type of the + returned value. + + + $sqlType (optional) + A SQLSRV_SQLTYPE_* constant that specifies the SQL Server data + type of the input value. + + + +
+
+
+ + options + + + An array specifing query property options. The supported keys are described + in the following table: + + + Query Options + + + + Key + Values + Description + + + + + QueryTimeout + A positive integer value. + Sets the query timeout in seconds. By default, the driver will + wait indefinitely for results. + + + SendStreamParamsAtExec + &true; or &false; (the default is &true;) + Configures the driver to send all stream data at execution (&true;), + or to send stream data in chunks (&false;). By default, the value is set + to &true;. For more information, see sqlsrv_send_stream_data. + + + Scrollable + SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_STATIC, SQLSRV_CURSOR_DYNAMIC, + or SQLSRV_CURSOR_KEYSET + See Specifying + a Cursor Type and Selecting Rows in the Microsoft SQLSRV documentation. + + + +
+
+
+
+
+
+ + + &reftitle.returnvalues; + + Returns a statement resource on success and &false; if an error occurred. + + + + + &reftitle.examples; + + + <function>sqlsrv_query</function> example + +"dbName", "UID"=>"username", "PWD"=>"password" ); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "INSERT INTO Table_1 (id, data) VALUES (?, ?)"; +$params = array(1, "some data"); + +$stmt = sqlsrv_query( $conn, $sql, $params); +if( $stmt === false ) { + die( print_r( sqlsrv_errors(), true)); +} +?> +]]> + + + + + + + &reftitle.notes; + + For statements that you plan to execute only once, use sqlsrv_query. + If you intend to re-execute a statement with different parameter values, use + the combination of sqlsrv_prepare and sqlsrv_execute. + + + + + &reftitle.seealso; + + + sqlsrv_prepare + sqlsrv_execute + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-rollback.xml b/reference/sqlsrv/functions/sqlsrv-rollback.xml new file mode 100644 index 0000000000..8b59547247 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-rollback.xml @@ -0,0 +1,130 @@ + + + + + sqlsrv_rollback + Rolls back a transaction that was begun with + sqlsrv_begin_transaction + + + &reftitle.description; + + boolsqlsrv_rollback + resourceconn + + + Rolls back a transaction that was begun with sqlsrv_begin_transaction + and returns the connection to auto-commit mode. + + + + + &reftitle.parameters; + + + + conn + + + The connection resource returned by a call to sqlsrv_connect. + + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + + &reftitle.examples; + + + <function>sqlsrv_rollback</function> example + + The following example demonstrates how to use sqlsrv_begin_transaction + together with sqlsrv_commit and sqlsrv_rollback. + + +"dbName", "UID"=>"userName", "PWD"=>"password"); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Begin the transaction. */ +if ( sqlsrv_begin_transaction( $conn ) === false ) { + die( print_r( sqlsrv_errors(), true )); +} + +/* Initialize parameter values. */ +$orderId = 1; $qty = 10; $productId = 100; + +/* Set up and execute the first query. */ +$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID) + VALUES (?, ?, ?)"; +$params1 = array( $orderId, $qty, $productId ); +$stmt1 = sqlsrv_query( $conn, $sql1, $params1 ); + +/* Set up and execute the second query. */ +$sql2 = "UPDATE InventoryTable + SET Quantity = (Quantity - ?) + WHERE ProductID = ?"; +$params2 = array($qty, $productId); +$stmt2 = sqlsrv_query( $conn, $sql2, $params2 ); + +/* If both queries were successful, commit the transaction. */ +/* Otherwise, rollback the transaction. */ +if( $stmt1 && $stmt2 ) { + sqlsrv_commit( $conn ); + echo "Transaction committed.
"; +} else { + sqlsrv_rollback( $conn ); + echo "Transaction rolled back.
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_begin_transaction + sqlsrv_commit + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-rows-affected.xml b/reference/sqlsrv/functions/sqlsrv-rows-affected.xml new file mode 100644 index 0000000000..d4e45366fd --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-rows-affected.xml @@ -0,0 +1,112 @@ + + + + + sqlsrv_rows_affected + Returns the number of rows modified by the last INSERT, UPDATE, or + DELETE query executed + + + &reftitle.description; + + mixedsqlsrv_rows_affected + resourcestmt + + + Returns the number of rows modified by the last INSERT, UPDATE, or DELETE + query executed. For information about the number of rows returned by a SELECT + query, see sqlsrv_num_rows. + + + + + &reftitle.parameters; + + + + stmt + + + The executed statement resource for which the number of affected rows is returned. + + + + + + + + + &reftitle.returnvalues; + + Returns the number of rows affected by the last INSERT, UPDATE, or DELETE query. + If no rows were affected, 0 is returned. If the number of affected rows cannot + be determined, -1 is returned. If an error occured, &false; is returned. + + + + + &reftitle.examples; + + + <function>sqlsrv_rows_affected</function> example + +"dbName", "UID"=>"username", "PWD"=>"password" ); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "UPDATE Table_1 SET data = ? WHERE id = ?"; + +$params = array("updated data", 1); + +$stmt = sqlsrv_query( $conn, $sql, $params); + +$rows_affected = sqlsrv_rows_affected( $stmt); +if( $rows_affected === false) { + die( print_r( sqlsrv_errors(), true)); +} elseif( $rows_affected == -1) { + echo "No information available.
"; +} else { + echo $rows_affected." rows were updated.
"; +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_num_rows + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-send-stream-data.xml b/reference/sqlsrv/functions/sqlsrv-send-stream-data.xml new file mode 100644 index 0000000000..87f665b5b3 --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-send-stream-data.xml @@ -0,0 +1,117 @@ + + + + + sqlsrv_send_stream_data + Sends data from parameter streams to the server + + + &reftitle.description; + + boolsqlsrv_send_stream_data + resourcestmt + + + Send data from parameter streams to the server. Up to 8 KB of data is sent + with each call. + + + + + &reftitle.parameters; + + + + stmt + + + A statement resource returned by sqlsrv_query or + sqlsrv_execute. + + + + + + + + + &reftitle.returnvalues; + + Returns &true; if there is more data to send and &false; if there is not. + + + + + &reftitle.examples; + + + <function>sqlsrv_send_stream_data</function> example + +"dbName", "UID"=>"username", "PWD"=>"password" ); +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( $conn === false ) { + die( print_r( sqlsrv_errors(), true)); +} + +$sql = "UPDATE Table_1 SET data = ( ?) WHERE id = 100"; + +// Open parameter data as a stream and put it in the $params array. +$data = fopen( "data://text/plain,[ Lengthy content here. ]", "r"); +$params = array( &$data); + +// Prepare the statement. Use the $options array to turn off the +// default behavior, which is to send all stream data at the time of query +// execution. +$options = array("SendStreamParamsAtExec"=>0); +$stmt = sqlsrv_prepare( $conn, $sql, $params, $options); + +sqlsrv_execute( $stmt); + +// Send up to 8K of parameter data to the server +// with each call to sqlsrv_send_stream_data. +$i = 1; +while( sqlsrv_send_stream_data( $stmt)) { + $i++; +} +echo "$i calls were made."; +?> +]]> + + + + + + + &reftitle.seealso; + + + sqlsrv_prepare + sqlsrv_query + + + + + + \ No newline at end of file diff --git a/reference/sqlsrv/functions/sqlsrv-server-info.xml b/reference/sqlsrv/functions/sqlsrv-server-info.xml new file mode 100644 index 0000000000..bda21c855f --- /dev/null +++ b/reference/sqlsrv/functions/sqlsrv-server-info.xml @@ -0,0 +1,122 @@ + + + + + sqlsrv_server_info + Returns information about the server + + + &reftitle.description; + + arraysqlsrv_server_info + resourceconn + + + Returns information about the server. + + + + + &reftitle.parameters; + + + + conn + + + The connection resource that connects the client and the server. + + + + + + + + + &reftitle.returnvalues; + + Returns an array as described in the following table: + + Returned Array + + + + CurrentDatabase + The connected-to database. + + + + + SQLServerVersion + The SQL Server version. + + + SQLServerName + The name of the server. + + + +
+
+
+ + + &reftitle.examples; + + + <function>sqlsrv_server_info</function> example + + $value) { + echo $key.": ".$value."
"; + } +} else { + die( print_r( sqlsrv_errors(), true)); +} +?> +]]> +
+
+
+
+ + + &reftitle.seealso; + + + sqlsrv_client_info + + + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/ini.xml b/reference/sqlsrv/ini.xml new file mode 100644 index 0000000000..d95df41597 --- /dev/null +++ b/reference/sqlsrv/ini.xml @@ -0,0 +1,85 @@ + + +
+ &reftitle.runtime; + &extension.runtime; + The following table lists the configuration options available in the SQLSRV + extension. For more information about these options, see + Handling SQLSRV Warnings and Errors. + + + SQLSRV &ConfigureOptions; + + + + &Name; + &Default; + &Changeable; + Changelog + + + + + sqlsrv.WarningsReturnAsErrors + 1 (&true;) + PHP_INI_ALL + Available since SQLSRV 1.0 + + + sqlsrv.LogSubsystems + 0 + PHP_INI_ALL + Available since SQLSRV 1.0 + + + sqlsrv.LogSeverity + 1 + PHP_INI_ALL + Available since SQLSRV 1.0 + + + +
+ + +
+ + +
+ + \ No newline at end of file diff --git a/reference/sqlsrv/reference.xml b/reference/sqlsrv/reference.xml new file mode 100644 index 0000000000..2862a92733 --- /dev/null +++ b/reference/sqlsrv/reference.xml @@ -0,0 +1,38 @@ + + + + + + + SQLSRV &Functions; + + + +&reference.sqlsrv.entities.functions; + + + + \ No newline at end of file diff --git a/reference/sqlsrv/setup.xml b/reference/sqlsrv/setup.xml new file mode 100644 index 0000000000..7c71df7560 --- /dev/null +++ b/reference/sqlsrv/setup.xml @@ -0,0 +1,99 @@ + + + + + &reftitle.setup; + + +
+ &reftitle.required; + + The SQLSRV extension can be used on the following operating systems: + + Windows Server 2003 Service Pack 1 + Windows XP Service Pack 3 + Windows Vista Service Pack 1 or later + Windows Server 2008 + Windows Server 2008 R2 + Windows 7 + + + + The SQLSRV extension requires that the Microsoft SQL Server 2008 R2 Native + Client be installed on the same computer that is running PHP. If the Microsoft + SQL Server 2008 R2 is not already installed, click the appropriate link below + to download it: + + Download the x86 package + Download the x64 package + + + + The SQLSRV download comes with several driver files. Which driver file you + use will depend on 3 factors: the PHP version you are using, whether you + are using thread-safe or non-thread-safe PHP, and whether your PHP installation + was compiled with the VC6 or VC9 compiler. For example, if you are running + PHP 5.3, you are using non-thread-safe PHP, and your PHP installation was + compiled with the VC9 compiler, you should use the php_sqlsrv_53_nts_vc9.dll + file. (You should use a non-thread-safe version compiled with the VC9 compiler + if you are using IIS as your web server). If you are running PHP 5.2, you are + using thread-safe PHP, and your PHP installation was compiled with the VC6 + compiler, you should use the php_sqlsrv_52_ts_vc6.dll file. + + + For more information about SQLSRV requirements, see + SQLSRV System Requirements. + +
+ + + + &reference.sqlsrv.configure; + + + + &reference.sqlsrv.ini; + + + +
+ &reftitle.resources; +
+ Connection resource + + A connection resource returned by sqlsrv_connect. + +
+
+ Statement resource + + A statement resource returned by sqlsrv_query or by + sqlsrv_prepare. + +
+
+ + +
+ + +