Home php教程 php手册 php SQL Server Authentication连接部分代码

php SQL Server Authentication连接部分代码

Jun 13, 2016 am 10:07 AM
authentication php server sql code Tutorial connect part

php教程 SQL Server Authentication连接部分代码
*/

$serverName = "(local)"; //数据库教程服务器地址
$uid = "pandao"; //数据库用户名
$pwd = "1987"; //数据库密码
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"test");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
    echo "连接失败!";
    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或者sqlserver2008

请先到此处下载驱动

http://www.microsoft.com/downloads/details.asp教程x?FamilyId=61BF87E0-D031-466B-B09A-6597C21A2E2A&displaylang=en

下载后解压文件

配置:

1.将解压的php_sqlsrv.dll 和 php_sqlsrv_ts.dll 放到PHP的扩展目录中(PHPEXT)。
2.编辑php.ini文件(在windows文件夹下),添加以下扩展:
extension=php_sqlsrv.dll
extension=php_sqlsrv_ts.dll
3.去掉;extension=php_mssql.dll前的分号

 SQL Server常用的有两种认证方式,一种是本地系统账户认证(Windows Authentication ),一种是使用用户名和密码(SQL Server Authentication ),第二种认证方式必须启用SQL Server的混合模式。

  1.Windows Authentication连接部分代码段:

    

   

             $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连接部分代码段:

      

             $serverName = "(local)";

             $uid = "dbusername";//数据库用户名

           $pwd = "dbuserpass";//数据库用户密码

             //下面的Database为数据库名

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

               }

      ?>

Statement of this Website
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

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles