PHP SQL Server Authentication Connection part code

Source: Internet
Author: User
Tags php tutorial

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";

}

?>

Related Article

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.