PHP Tutorial SQL Server Authentication Connection Section Code
*/
$serverName = "(local)";//Database Tutorial server address
$uid = "Pandao"; Database user Name
$pwd = "1987"; Database Password
$connectionInfo = Array ("UID" = = $uid, "PWD" = = $pwd, "Database" = "test");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn = = False)
{
echo "Connection failed! ";
Die (Print_r (Sqlsrv_errors (), true));
}
$query = sqlsrv_query ($conn, "select TOP nid,title,content from Test.dbo.news");
while ($row = Sqlsrv_fetch_array ($query)) {
echo $row [' nid ']. -----". $row [' title ']."
";
}
?>
sqlserver2005 or sqlserver2008
Please download the driver here first
http://www.microsoft.com/downloads/details.asp tutorial x? familyid=61bf87e0-d031-466b-b09a-6597c21a2e2a&displaylang=en
Unzip files after download
Configuration:
1. Place the extracted php_sqlsrv.dll and php_sqlsrv_ts.dll in the PHP extension directory (phpext).
2. Edit the php.ini file (under the Windows folder) and add the following extensions:
Extension=php_sqlsrv.dll
Extension=php_sqlsrv_ts.dll
3. Remove the semicolon before Extension=php_mssql.dll
There are two kinds of authentication methods commonly used in SQL Server, one is Local System account authentication (Windows authentication), one is using user name and password (SQL Server authentication), the second authentication method must enable SQL The mixed mode of the server.
1.Windows Authentication Connection Section code snippet:
$serverName = "(local)";
$connectionInfo = Array ("Database" = "Testinginfo", "connectionpooling" =>false);
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if (! $conn) {
echo "O no!!!!!";
Die (Print_r (Sqlsrv_errors (), true));
}else{
echo "Yes done";
}
?>
2.SQL Server Authentication Connection Section code snippet:
$serverName = "(local)";
$uid = "Dbusername";//Database user name
$pwd = "Dbuserpass";//Database user password
The database name below is
$connectionInfo = Array ("UID" = = $uid, "PWD" = = $pwd, "Database" = "dbname");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if (! $conn) {
echo "O no!!!!!!!";
Die (Print_r (Sqlsrv_errors (), true));
}else{
echo "Yes done";
}
?>
http://www.bkjia.com/PHPjc/630855.html www.bkjia.com true http://www.bkjia.com/PHPjc/630855.html techarticle PHP Tutorial SQL Server Authentication Connection Section code */$serverName = (local);//Database tutorial server address $uid = Pandao;//database user name $pwd = 1987;//Data Library password ...