Using SQL Server Authentication in PHP to connect to a database _php tutorial

Source: Internet
Author: User
When you connect to SQL Server, SQL Server Driver for PHP supports SQL Server authentication. The following points must be considered when connecting to SQL Server using SQL Server Authentication:

SQL server Mixed Mode authentication must be enabled on the server.
The UID and PWD connection properties must be set when attempting to establish a connection. The UID and PWD must be mapped to a valid SQL Server user and password.
Attention:

The password containing the closing curly brace (}) must be escaped with another closing brace. For example, if the SQL Server password is "Pass}word", the value of the PWD connection property must be set to "Pass}}word".
The following precautions should be taken when connecting to SQL Server using SQL Server Authentication:
Let's look at a simple example:

The code is as follows Copy Code

$serverName = "(local)";
$uid = ' xxxx ';
$pwd = ' xxxx ';
$connectionInfo = Array ("UID" = = $uid,
"PWD" = $pwd,
"Database" = "AdventureWorks");

$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn = = = False)
{
echo "Could not connect to the database.";
Die (Print_r (Sqlsrv_errors (), true));
}

$tsql = "Select CONVERT (varchar (+), 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 "Logged in User:". $row [0];

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

http://www.bkjia.com/PHPjc/632944.html www.bkjia.com true http://www.bkjia.com/PHPjc/632944.html techarticle When you connect to SQL Server, SQL Server Driver for PHP supports SQL Server authentication. The following points must be considered when connecting to SQL Server using SQL Server Authentication: Must ...

  • 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.