Solve the problem that php5.3 cannot connect to the mssql database _ PHP Tutorial

Source: Internet
Author: User
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
...
}

...

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.