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 ']." <br/> ";
}
?>
sqlserver2005 or sqlserver2008.
Please go here first to download the driver
http://www.microsoft.com/downloads/details.asp tutorial x? familyid=61bf87e0-d031-466b-b09a-6597c21a2e2a&displaylang=en
Extract files after downloading
Configuration:
1. Place the extracted php_sqlsrv.dll and php_sqlsrv_ts.dll into the extended directory of PHP (Phpext).
2. Edit the php.ini file (under Windows folder) and add the following extensions:
Extension=php_sqlsrv.dll
Extension=php_sqlsrv_ts.dll
3. Remove; Extension=php_mssql.dll before the semicolon
SQL Server is commonly used for two authentication methods, one is the local System account authentication (Windows authentication), one is the use of user name and password (SQL Server authentication), the second authentication method must enable SQL The mixed mode of the server.
1.Windows Authentication Connection Part code snippet:
<?php
$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:
<?php
$serverName = "(local)";
$uid = "Dbusername";//Database user name
$pwd = "Dbuserpass";//Database user password
The following databases are database names
$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";
}
?>