Php5.3 cannot connect to the mssql Database. php5.3mssql _ PHP Tutorial

Source: Internet
Author: User
Php5.3 cannot connect to the mssql database solution, php5.3mssql. Php5.3 cannot connect to the mssql Database. php5.3mssql this article describes how php5.3 cannot connect to the mssql database. Share it with you for your reference. The specific analysis is as follows: php5.3 cannot connect to the mssql database solution, php5.3mssql

This example describes how php5.3 cannot connect to the mssql database. 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.

Examples in this article describes how php5.3 cannot connect to the mssql database. Share it with you for your reference. The specific analysis is as follows...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.