This article mainly introduces how php5.3 cannot connect to the mssql Database. It provides corresponding solutions for php5.3 and does not support the mssql_connect function, which has some reference value, for more information about how to connect php5.3 to the mssql database, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
Since php5.3 and later, the system does not support mssql_connect function connection. 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, and open php. ini and add it at the end:
The code is as follows:
[PHP_PDO_SQLSRV]
Extension = php_pdo_sqlsrv_53_nts_vc6.dll
[PHP_SQLSRV]
Extension = php_sqlsrv_53_nts_vc6.dll
After saving the file, restart apache and attach a simple php connection example. the code is as follows:
The code is as follows:
<? Php
$ 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. I did a test on windows server 2008 and php5.4 or above, but the test was not successful.
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:
The code 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-extracting file and click the API Reference node.
In addition, the code for reading an odb connection method is as follows:
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
...
}
I hope this article will help you with php programming.