


php SQL Server Authentication connection part code_PHP tutorial
Jul 13, 2016 pm 05:04 PMphp 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']."<br/>";
}
?>
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
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:
<?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 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";
}
?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
