This example describes how PHP uses SQL Server to verify the connection to the database. Share to everyone for your reference. The specific analysis is as follows:
When you connect to SQL Server, SQL Server Driver for PHP supports SQL Server authentication, and you must consider the following points when you use SQL Server Authentication to connect to SQL Server.
SQL Server mixed Mode authentication must be enabled on the server, and the UID and PWD connection properties must be set when attempting to establish a connection, and the UID and PWD must be mapped to a valid SQL server user and password.
Note: The password that contains 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: Here is a simple example of the code below.
<?php $serverName = "(local)"; $uid = ' xxxx '; $pwd = ' xxxx '; $connectionInfo = Array ("UID" = = $uid, "PWD" = = $pwd, "Database" = "AdventureWorks"); $conn = Sqlsrv_connect ($serverName, $connectionInfo); if ($conn = = = False) { echo "Cannot 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);?>
I hope this article is helpful to everyone's PHP programming.