PHP php_mssql.dll files cannot meet the requirements of SQL server2005 and later versions. Microsoft also released the SQL Server Driver for PHP for corresponding support.
SQL Server Driver for PHP supports different php versions.
1. SQL Server Driver for PHP2.0 is applicable to PHP 5.2.x.
: Http://download.csdn.net/detail/xxhysj/4793158
2. SQL Server Driver for PHP3.0 is applicable to PHP 5.3.x.
: Http://download.csdn.net/detail/xxhysj/4793176
The procedure is as follows:
1) download the driver package at the preceding address;
2) decompress the DLL file to the PHP extension_dir directory.
Extension_dir = "X: \ PHP \ ext"
3) reference the corresponding dynamic link library file in the php. ini configuration file.
Extension = php_sqlsrv_52_ts_vc6.dll
Extension = php_pdo_sqlsrv_52_ts_vc6.dll
Extension = php_pdo.dll
4) Restart Apache
5) connect to the database
/* Specify the server and connection string attributes. */$serverName = "(local)";$connectionInfo = array( "Database"=>"AdventureWorks");/* Connect using Windows Authentication. */$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn === false ){ echo "Unable to connect.</br>"; die( print_r( sqlsrv_errors(), true));}/* Query SQL Server for the login of the user accessing thedatabase. */$tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())";$stmt = sqlsrv_query( $conn, $tsql);if( $stmt === false ){ echo "Error in executing query.</br>"; die( print_r( sqlsrv_errors(), true));}/* Retrieve and display the results of the query. */$row = sqlsrv_fetch_array($stmt);echo "User login: ".$row[0]."</br>";/* Free statement and connection resources. */sqlsrv_free_stmt( $stmt);sqlsrv_close( $conn);?>
Note: API reference (SQL Server Driver for PHP)
The API name used for SQL Server Driver for PHP is sqlsrv. All sqlsrv functions start with sqlsrv _, followed by a verb or noun. The function followed by the verb is used to perform a specific operation, and the function followed by the noun is used to return metadata in a specific form.
SQL Server Driver for PHP includes the following functions:
Function |
Description |
Sqlsrv_begin_transaction |
Start the transaction. |
Sqlsrv_cancel |
Cancel the statement, and discard all outstanding results of the corresponding statement. |
Sqlsrv_client_info |
Provide information about the client. |
Sqlsrv_close |
Close the connection. Releases all resources associated with the corresponding connection. |
Sqlsrv_commit |
Commit a transaction. |
Sqlsrv_configure |
Modify error handling and logging configurations. |
Sqlsrv_connect |
Create a connection and open it. |
Sqlsrv_errors |
Returns the error and/or warning information about the previous operation. |
Sqlsrv_execute |
Run the predefined statement. |
Sqlsrv_fetch |
Make the data in the next row readable. |
Sqlsrv_fetch_array |
The data of the next row is retrieved in the form of a numerical index array, an associated array, or two arrays. |
Sqlsrv_fetch_object |
Retrieves the data of the next row as an object. |
Sqlsrv_field_metadata |
Return field metadata. |
Sqlsrv_free_stmt |
Close the statement. Release all resources associated with the corresponding statement. |
Sqlsrv_get_config |
Returns the value of the specified configuration. |
Sqlsrv_get_field |
Search fields in the current row by index. You can specify the PHP return type. |
Sqlsrv_has_rows |
Check whether the result set has one or more rows. |
Sqlsrv_next_result |
Make the next result available for processing. |
Sqlsrv_num_rows |
Number of rows in the report result set. |
Sqlsrv_num_fields |
Number of fields in the search activity result set. |
Sqlsrv_prepare |
Prepare a Transact-SQL query, but do not execute the query. Implicitly bind parameters. |
Sqlsrv_query |
Prepare and execute the Transact-SQL query. |
Sqlsrv_rollback |
Roll back the transaction. |
Sqlsrv_rows_affected |
Returns the number of modified rows. |
Sqlsrv_send_stream_data |
Each time a function is called, a maximum of eight thousand bytes (8 KB) of data can be sent to the server. |
Sqlsrv_server_info |
Provide information about the server. |
Address: http://blog.csdn.net/xxhysj/article/details/8207982