Php uses sqlserver to verify the method of connecting to the database. Php uses sqlserver to verify the connection to the database. sqlserver this article describes how php uses sqlserver to verify the connection to the database. Share it with you for your reference. For details, see the SQL server Verification Method for php to connect to the database.
This example describes how php uses SQL server to verify database connection. Share it with you for your reference. The specific analysis is as follows:
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 points.
You must enable SQL Server hybrid authentication on the Server. when trying to establish a connection, you must set the UID and PWD connection Attributes. the UID and PWD must be mapped to a valid SQL Server user and password.
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 preventive measures. the following code is a simple example:
The code is as follows:
<? Php
$ 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 );
?>
I hope this article will help you with php programming.
This article describes how php uses SQL server to verify database connection. Share it with you for your reference. The specific analysis is as follows...