PHP Connection mssql2008/2005 Database (SQLSRV) configuration

Source: Internet
Author: User
Tags sql server driver

1. Download the extension

(1) to go to the official download of a SQL Server Driver for PHP extension pack, I am here to download the http://www.microsoft.com/en-us/download/details.aspx?id=20098 " Remember to download it as if you want to install and then unzip the "(2) You can also download directly from this site (i downloaded before, from Microsoft Official)" Click Direct Download "will download the RAR file after decompression you will get a bunch of. dll files

Download the driver, download and install the release program, which has the following files:

Php_pdo_sqlsrv_52_nts.dll

Php_pdo_sqlsrv_52_ts.dll

Php_pdo_sqlsrv_53_nts_vc6.dll

Php_pdo_sqlsrv_53_nts_vc9.dll

Php_pdo_sqlsrv_53_ts_vc6.dll

Php_pdo_sqlsrv_53_ts_vc9.dll

Php_sqlsrv_52_nts.dll

Php_sqlsrv_52_ts.dll

Php_sqlsrv_53_nts_vc6.dll

Php_sqlsrv_53_nts_vc9.dll

Php_sqlsrv_53_ts_vc6.dll

Php_sqlsrv_53_ts_vc9.dll

Sqlserverdriverforphp.chm (manual, English good enough, can see, hehe)

Sqlserverdriverforphp_license.rtf

Sqlserverdriverforphp_readme.htm (Readme file)

2. Add an extension

According to (VC6/VC9) need to choose the extension, my environment is Wamp (php5.2.6/apache2.2.8), I chose Php_sqlsrv_52_ts_vc6.dll,php_pdo_sqlsrv_52_ts_ Vc6.dll These two files, copy to the Ext directory under the WAMP installation directory, my ext directory is in wamp/bin/php/php5.2.6/ext/

3. Configure PHP.ini

(1) Add the following two extensions in the php.ini dynamic extensions: extension=php_sqlsrv_52_ts_vc6.dll EXTENSION=PHP_PDO_SQLSRV_52_TS_VC 6.dll

(2) Extension=php_pdo.dll; remove, turn on the PDO connection extension

(3) Restart Apache 4. Connect to Database (PDO connection)

The code is as follows Copy Code

<?php $servern = "Sfkfk27el8fj\sqltry";   $coninfo =array ("Database" = "Try2", "UID" = "sa", "PWD" = "123");   $conn =sqlsrv_connect ($servern, $coninfo) or Die ("Connection failed!");   $val =sqlsrv_query ($conn, "select * from usertable"); while ($row =sqlsrv_fetch_array ($val)) {echo $row [1]. "   <br/> "; } sqlsrv_close ($conn); ?>

5. Example

Examples of links:

mssql_lib.php

The code is as follows Copy Code

<?php

Class DB {var $con = null; function __construct ($dbhost, $dbuser, $dbpass, $dbname) {$connectionInfo = Array ("UID" = + $dbuser, "PWD" + = $DBPA         SS, "Database" = $dbname);     $this->con = Sqlsrv_connect ($dbhost, $connectionInfo); }

function query ($sql) {$result = sqlsrv_query ($this->con, $sql); }

    function GetRow ($sql) {        $result = sqlsrv_query ($ This->con, $sql);         $arr = Array ();         while ($row = Sqlsrv_fetch_array ($result))          {            $arr [] = $row;         }         return $arr [0];    }

function GetAll ($sql) {$result = sqlsrv_query ($this->con, $sql);         $arr = Array ();         while ($row = Sqlsrv_fetch_array ($result)) {$arr [] = $row;     } return $arr; }

function __destruct () {unset ($con); }

} test.php

Simple call $db = new db (Db_host, Db_user, Db_pass, db_name); $sql = "SELECT * from Crm_order_batch where (status=0 or status was null) and lock_id is not NULL"; $orders _add_list = $db->getall ($sql);

PHP Connection mssql2008/2005 Database (SQLSRV) configuration

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.