php使用sql server验证连接数据库的方法,sqlserver
本文实例讲述了php使用sql server验证连接数据库的方法。分享给大家供大家参考。具体分析如下:
当您连接到 SQL Server 时,SQL Server Driver for PHP 支持 SQL Server 身份验证,在使用 SQL Server 身份验证连接到 SQL Server 时必须考虑以下几点.
必须对服务器启用 SQL Server 混合模式身份验证,在尝试建立连接时必须设置 UID 和 PWD 连接属性,UID 和 PWD 必须映射到有效的 SQL Server 用户和密码.
注意:包含右大括号 (}) 的密码必须使用另一个右大括号进行转义,例如,如果 SQL Server 密码为“pass}word”,则 PWD 连接属性的值必须设置为“pass}}word”.
在使用 SQL Server 身份验证连接到 SQL Server 时应采取以下预防措施,下面看一个简单的实例,代码如下:
复制代码 代码如下:
$serverName = "(local)";
$uid = 'xxxx';
$pwd = 'xxxx';
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "无法连接数据库.";
die( print_r( sqlsrv_errors(), true));
}
$tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "查询错误.";
die( print_r( sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt);
echo "登录的用户: ".$row[0];
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
