Use SQL Server Verification in php to connect to the database _ PHP Tutorial

Source: Internet
Author: User
Tags sql server driver
Use SQL Server Verification in php to connect to the database. When you connect to SQLServer, SQLServerDriverforPHP supports SQLServer authentication. When connecting to SQL Server using SQL Server Authentication, you must consider the following: when you connect to SQL Server, SQL Server Driver for PHP supports SQL Server authentication. When using SQL Server Authentication to connect to SQL Server, you must consider the following:

You must enable SQL Server hybrid authentication on the Server.
When trying to establish a connection, you must set the UID and PWD connection properties. UID and PWD must be mapped to valid SQL Server users and passwords.
Note:

The password containing the right braces (}) must be escaped using another right braces. For example, if the SQL Server password is "pass} word", the value of the PWD connection attribute must be set to "pass} word ".
When using SQL Server Authentication to connect to SQL Server, take the following precautions:
Here is a simple example:

The code is as follows:

$ ServerName = "(local )";
$ Uid = 'xxxx ';
$ Pwd = 'xxxx ';
$ ConnectionInfo = array ("UID" => $ uid,
"PWD" => $ pwd,
"Database" => "AdventureWorks ");

$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );
If ($ conn = false)
{
Echo "unable to connect to database .";
Die (print_r (sqlsrv_errors (), true ));
}

$ Tsql = "select convert (varchar (32), SUSER_SNAME ())";
$ Stmt = sqlsrv_query ($ conn, $ tsql );
If ($ stmt = false)
{
Echo "query error .";
Die (print_r (sqlsrv_errors (), true ));
}

$ Row = sqlsrv_fetch_array ($ stmt );
Echo "login user:". $ row [0];

Sqlsrv_free_stmt ($ stmt );
Sqlsrv_close ($ conn );
?>

When using SQL Server, SQL Server Driver for PHP supports SQL Server authentication. When using SQL Server Authentication to connect to SQL Server, you must consider the following: required...

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.