Solve the problem that php5.3 cannot connect to the mssql database. Since php5.3 and later, the system does not support mssql_connect function connection. Previously, we can also use the com interface to implement this function, now I will introduce how to solve the problem that php5.3 cannot connect to the mssql database, and the system does not support the mssql_connect function connection since php5.3. in the past, I also talked about using the com interface, now I will introduce another method to solve the problem that php5.3 cannot connect to the mssql database.
In windows, versions later than PHP5.3 do not support mssql extension.
First http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx click get it to download SQLSRV20.EXE.
Decompress the file to ext, the extension folder of php.
Open php. ini and add at the end
[PHP_PDO_SQLSRV]
Extension = php_pdo_sqlsrv_53_nts_vc6.dll
[PHP_SQLSRV]
Extension = php_sqlsrv_53_nts_vc6.dll
Save and restart apache. The following is an example of a simple php connection:
The code is as follows: |
|
$ ServerName = "(127.0.0.1 )"; $ ConnectionInfo = array ("UID" => "root ", "PWD" => "root2010 ", "Database" => "master "); $ Conn = sqlsrv_connect ($ serverName, $ connectionInfo ); If ($ conn) { Echo "Connection established. n "; } Else { Echo "Connection cocould not be established. n "; Die (print_r (sqlsrv_errors (), true )); } ?> |
I am using the wamp5.1 integrated installation package. Test on windows server 2008. Php5.4 or later versions fail to be tested.
If you use this extension to connect to SQL server 2005 or a later version of SQL server (such as SQL server 2008), you also need to first install SQL Server Native Client: http://download.microsoft.com/download/0/E/6/0E67502A-22B4-4C47-92D3-0D223F117190/sqlncli.msi on the machine
This extension adds a series of functions starting with sqlsrv _ to php. the Function reference is as follows:
Sqlsrv_begin_transaction
Sqlsrv_cancel
Sqlsrv_client_info
Sqlsrv_close
Sqlsrv_commit
Sqlsrv_configure
Sqlsrv_connect
Sqlsrv_errors
Sqlsrv_execute
Sqlsrv_fetch
Sqlsrv_fetch_array
Sqlsrv_fetch_object
Sqlsrv_fetch_metadata
Sqlsrv_free_stmt
Sqlsrv_get_config
Sqlsrv_get_field
Sqlsrv_has_rows
Sqlsrv_next_result
Sqlsrv_num_fields
Sqlsrv_num_rows
Sqlsrv_prepare
Sqlsrv_query
Sqlsrv_rollback
Sqlsrv_rows_affected
Sqlsrv_send_stream_data
Sqlsrv_server_info
For more details, you can find the SQLServerDriverForPHP. chm help file in the self-decompressed file and click the API Reference node.
Another method of odb connection
The code is as follows: |
|
$ Dbhost = "; $ Dbuser = "; // your mssql user name $ Dbpass = "; // your mssql password $ Dbname = "; // your mssql database name $ Connect = odbc_connect ("Driver = {SQL Server}; Server = $ dbhost; Database = $ dbname", "$ dbuser", "$ dbpass "); $ SQL = "select * from content "; $ Exec = odbc_exec ($ connect, $ SQL ); While ($ row = (odbc_fetch_array ($ exec ))) { $ Row ['id'] //? Field value ... } |
...