PHP uses sql server to verify the method of connecting to the database, sqlserver_PHP tutorial

WBOY
Release: 2016-07-13 10:10:48
Original
861 people have browsed it

php uses sql server to verify the method of connecting to the database, sqlserver

The example in this article describes how PHP uses sql server to verify the connection to the database. Share it with everyone for your reference. The specific analysis is as follows:

SQL Server Driver for PHP supports SQL Server Authentication when you connect to SQL Server. 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 trying to establish a connection, and the UID and PWD must map to a valid SQL Server user and password.

Note: Passwords containing a closing brace (}) must be escaped with another closing brace, for example, if the SQL Server password is "pass}word", the value of the PWD connection attribute 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 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 "Logged in user: ".$row[0];

sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932485.htmlTechArticlephp uses sql server to verify the method of connecting to the database, sqlserver This article describes the example of php using sql server to verify the method of connecting to the database . Share it with everyone for your reference. Specific analysis is as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template