PHP連接MSSQL資料庫(SQLSRV)實例
PHP連接MSSQL2008/2005資料庫與以往的連接mssql2000是不一樣的,連接mssql2008/2005是需要自己添加PHP對MSSQL連接的驅動擴充了,而我們常用的hp.ini中的extension=php_mssql.dll擴充只適用連接於MSSQL2000,下面我們就來看看對此的解決方案。
1.下載擴充功能
(1)去官方下載一個SQL Server Driver for PHP的擴充包,我是在這裡下載的http://www.microsoft.com/en- us/download/details.aspx?id=20098【記得下載後好像是要先安裝然後再解壓縮】
(2)您也可以直接從本站下載(我之前下載的,來自microsoft官方)【點擊此處直接下載】
將下載下來的rar文件解壓縮後你就會得到一堆的.dll文件
下載驅動程序,下載後安裝釋放程序,裡面有以下文件:
php_pdo_sqlsrv_52_nts.dll
php_pdo_sqlsrv_52_ts.dll
php_pdo_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_nts_vc6.dll
php_pdo_llsqlsrv_53_nts_nts_vc6.dll
php_pdo_llsqlsrv_53_nts_nts_vc6。 3_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
SerServerDriverForPHfchmrv_53_ts_vc9.dll
ServerDrive ##SQLServerDriverForPHP_Readme.htm(自述文件)
extension=php_sqlsrv_52_ts_vc6.dll
extension=php_pdo_sqlsrv_5_ll
extension=php_pdo_sqlsrv_5_ll
extension=php_pdo_sqlsrv_5_llts_#6. 2)將;extension=php_pdo.dll前面的;去掉,開啟pdo連線擴充
(3)重新啟動apache
4.連線資料庫(pdo連線)
<?php $servern="SFKFK27EL8FJ\SQLTRY"; $coninfo=array("Database"=>"try2","UID"=>"sa","PWD"=>"123"); $conn=sqlsrv_connect($servern,$coninfo) or die ("连接失败!"); $val=sqlsrv_query($conn,"select * from usertable"); while($row=sqlsrv_fetch_array($val)){ echo $row[1]."<br />"; } sqlsrv_close($conn); ?>
5.範例
連結範例:
mssql_lib.php檔案如下:
<?php class DB { var $con = null; function __construct($dbhost,$dbuser,$dbpass,$dbname) { $connectionInfo = array("UID"=>$dbuser,"PWD"=>$dbpass,"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頁面如下:
//简单调用 $db = new DB(DB_HOST, DB_USER, DB_PASS, DB_NAME); $sql = "select * from crm_order_batch where (status=0 or status is null) and lock_id is not null "; $orders_add_list = $db->getAll($sql);
相關推薦:
以上是PHP連接MSSQL資料庫(SQLSRV)實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP 8.4 帶來了多項新功能、安全性改進和效能改進,同時棄用和刪除了大量功能。 本指南介紹如何在 Ubuntu、Debian 或其衍生版本上安裝 PHP 8.4 或升級到 PHP 8.4

CakePHP 是 PHP 的開源框架。它旨在使應用程式的開發、部署和維護變得更加容易。 CakePHP 基於類似 MVC 的架構,功能強大且易於掌握。模型、視圖和控制器 gu

Visual Studio Code,也稱為 VS Code,是一個免費的原始碼編輯器 - 或整合開發環境 (IDE) - 可用於所有主要作業系統。 VS Code 擁有大量針對多種程式語言的擴展,可以輕鬆編寫
