Home  >  Article  >  Backend Development  >  php SQL Server Authentication connection part code_PHP tutorial

php SQL Server Authentication connection part code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:21938browse

php tutorial SQL Server Authentication connection part code
*/

$serverName = "(local)"; //Database tutorial server address
$uid = "pandao"; //Database username
$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 10 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.aspTutorialx?FamilyId=61BF87E0-D031-466B-B09A-6597C21A2E2A&displaylang=en

Unzip the file after downloading

Configuration:

1. Place the decompressed php_sqlsrv.dll and php_sqlsrv_ts.dll into the PHP extension directory (PHPEXT).
2. Edit the php.ini file (under the windows folder) and add the following extension:
extension=php_sqlsrv.dll
extension=php_sqlsrv_ts.dll
3. Remove the semicolon

before extension=php_mssql.dll

There are two commonly used authentication methods in SQL Server. One is local system account authentication (Windows Authentication), and the other is using user name and password (SQL Server Authentication). The second authentication method must enable the mixed mode of SQL Server. .

1. Windows Authentication connection part 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 part code snippet:

                                           

$serverName = "(local)";

                $uid = "dbusername";//Database user name

$pwd = "dbuserpass";//Database user password

//The following Database is the database name

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

          }

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630855.htmlTechArticlephp tutorial SQL Server Authentication connection part code*/ $serverName = (local); //Database tutorial server address$ uid = pandao; //Database username $pwd = 1987; //Database password...
Statement:
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