PHP SQL Server Authentication Connection section Code _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.