PHP Connect SQL Server method

Source: Internet
Author: User
Tags sql server driver

1. Download SQL Server Driver for PHP, unzip, copy the Php_pdo_sqlsrv_53_ts_vc9.dll and Php_sqlsrv_53_ts_vc9.dll to the Php-->ext folder

2. Modify the php.ini file,

Extension=php_pdo_sqlsrv_53_ts_vc9.dll

Extension=php_sqlsrv_53_ts_vc9.dll

3. Test whether Setup is successful

Perform a view of Phpinfo () in PHP sqlsrv

4.demo Test

<?PHP$type=$_get["TP"];$param=$_get["PRM"];if(isset($_get["TP"]) &&isset($_get["PRM"]) ){    $userInfo=NewUserInfo (); if($type= = "Select" &&$param= = "All")        Echo $userInfo-SelectAll (); }classuserinfo{ Public functionSelectAll () {$serverName= "192.168.1.8";//Database server address        $uid= "SA";//Database user name        $pwd= "1234?";//Database Password        $connectionInfo=Array("UID" =$uid, "PWD" =$pwd, "Database" = "DB"); $conn= Sqlsrv_connect ($serverName,$connectionInfo); if($conn==false)        {            Echo"Connection Failed! ";  die(Print_r(Sqlsrv_errors (),true)); }                $res=""; $query= Sqlsrv_query ($conn, "SELECT * from UserInfo");  while($row= Sqlsrv_fetch_array ($query))        {          $res.=$row[0]. ",".$row[1]. "|"; }        return $res; }}?>


ok~~~~~

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.