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. 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 property must be set to "pass}}word".
You should take the following precautions when connecting to SQL Server using SQL Server Authentication:
Let’s look at a simple example:
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 "无法连接数据库.";
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);
?>
|
|
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 "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 )
{
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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632944.htmlTechArticleThe 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: Must...
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