欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

PHP中怎么連接MSSQL

今天就跟大家聊聊有關(guān)PHP中怎么連接MSSQL,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)專注于鲅魚圈企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),商城網(wǎng)站建設(shè)。鲅魚圈網(wǎng)站建設(shè)公司,為鲅魚圈等地區(qū)提供建站服務(wù)。全流程按需制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

PHP連接MSSQL的實(shí)現(xiàn)方法。ms SQL是指微軟的SQLServer數(shù)據(jù)庫(kù)服務(wù)器,它是一個(gè)數(shù)據(jù)庫(kù)平臺(tái),提供數(shù)據(jù)庫(kù)的從服務(wù)器到終端的完整的解決方案,其中數(shù)據(jù)庫(kù)服務(wù)器部分,是一個(gè)數(shù)據(jù)庫(kù)管理系統(tǒng),用于建立、使用和維護(hù)數(shù)據(jù)庫(kù)。SQL Server一開始并不是微軟自己研發(fā)的產(chǎn)品,而是當(dāng)時(shí)為了要和IBM競(jìng)爭(zhēng)時(shí),與Sybase合作所產(chǎn)生的,其最早的發(fā)展者是Sybase,同時(shí)微軟也和Sybase合作過 SQL Server 4.2版本的研發(fā),微軟亦將SQL Server 4.2移植到Windows NT(當(dāng)時(shí)為3.1版),在與Sybase終止合作關(guān)系后,自力開發(fā)出SQL Server 6.0版,往后的SQL Server即均由微軟自行研發(fā)。

PHP連接MSSQL的實(shí)現(xiàn)方法

為了能讓PHP連接MSSQL,系統(tǒng)需要安裝MSSQL,PHP,且在PHP.ini中的配置中,將 ;extension=php_mssql.dll前面的;去掉

1.連接MSSQL

$conn=mssql_connect("實(shí)例名或者服務(wù)器IP","用戶名","密碼");

//測(cè)試連接

if($conn)

{

echo "連接成功";

}

2.選擇要連接的數(shù)據(jù)庫(kù)

1mssql_select_db("dbname");

3.執(zhí)行查詢

$rs = mssql_query("select top 1 id,username from tbname",$conn);

// 或者直接執(zhí)行update,insert等語(yǔ)句,可以不用為返回結(jié)果賦值

mssql_query("update tbname set username='niunv' where id=1");

4.獲取記錄集行數(shù)

1echo mssql_num_rows($rs);

5.獲取記錄集

if($row=mssql_fetch_array($rs))

{

$id = $row[0];//獲取ID字段值

$username = $row[1];//獲取username字段值

}

6.獲取新增記錄的ID

將id字段設(shè)置為IDENTITY字段,執(zhí)行insert語(yǔ)句以后,就會(huì)產(chǎn)生一個(gè) @@IDENTITY 全局變量值,查詢出來(lái)就是最后一條新增記錄的ID了.

mssql_query("insert into tbname(username) values ('nv')",$conn);

$rs = mssql_query("select @@IDENTITY as id",$conn);

if($row=mssql_fetch_array($rs))

{

echo $row[0];

}

7.釋放記錄集

1mssql_free_result($rs);

8.關(guān)閉連接

1mssql_close($conn);

注:用PHP操作MSSQL比在ASP連接MySQL要簡(jiǎn)單,所以,當(dāng)需要MSSQL與MYSQL并存時(shí),用PHP連接MSSQL來(lái)操作MYSQL與MSSQL并存比較簡(jiǎn)單好用.如果是ASP連接MYSQL,需要安裝一個(gè)MYSQL驅(qū)動(dòng),默認(rèn)windows的ODBC沒有安裝,很遺憾...

在web服務(wù)器上至少安裝了mssql的客戶端

打開php.ini把;extension=php_mssql.dll 前面的分號(hào)去掉

有必要話:需要制定extension_dir

推薦使用 php<=4.0.9 server="$Server;" this-="">userName = $UserName;

$this->passWord = $PassWord;

$this->dataBase = $DataBase;

}

/**

*數(shù)據(jù)庫(kù)連接

**/

function db_connect(){

$this->linkID = mssql_pconnect($this->server,$this->userName,$this->passWord);

if(!$this->linkID){

$this->ER = "db_connect($this->server,$this->userName,$this->passWord) error";

return 0;

}

if (!mssql_select_db($this->dataBase,$this->linkID)) {

$this->ER = "mssql_select_db($this->dataBase,$this->lastInsertID) error";

return 0;

}

return $this->linkID;

}

/**public

* function: Check the database, if exist then select

* exist: return 1

* not exist: return 0

*/

function selectDatabase(){

if(mssql_select_db($this->dataBase))

return 1;

else

return 0;

}

/**

*數(shù)據(jù)操作

**/

function query($Str){

if ($this->linkID == 0) {

$this->ER = "數(shù)據(jù)庫(kù)還沒有連接!!";

}

$this->queryResult = mssql_query($Str);

//$this->queryResult = mssql_query($Str,$this->linkID);

if (!$this->queryResult) {

$this->ER = "$Str.沒有操作成功,query error!!";

return 0;//****************對(duì)于php 4.3.9以上版本的錯(cuò)誤用1

}

return $this->queryResult;

}

/**

*數(shù)據(jù)獲取

**/

function fetch_array($result){

if($result != "") $this->queryResult = $result;

$rec =mssql_fetch_array($this->queryResult);

if(is_array($rec)){

return $rec;

}

//$this->ER = "沒有獲取數(shù)據(jù)!";

return 0;

}

/**public

* function: Free the Query Result

* success return 1

* failed: return 0

*/

function freeResult($result=""){

if($result != "") $this->queryResult = $result;

return mssql_free_result($this->queryResult);

}

/**

*獲取影響的的行數(shù)

*獲取操作過的行數(shù)

**/

function num_rows($result=""){

if ($result != "") {

$this->queryResult = $result;

$row = mssql_num_rows($this->queryResult);

return $row;

}

}

/**

*獲取查詢結(jié)果---多個(gè)

**/

function result_ar($str=''){

if (empty($str)) {

return 0;

}

$back = array();

$this->queryResult = $this->query($str);

while ($row = $this->fetch_array($this->queryResult)) {

$back[] = $row;

}

return $back;

}

/**

*數(shù)據(jù)庫(kù)信息分頁(yè)

*$Result 數(shù)據(jù)庫(kù)操作

*str ==sql語(yǔ)句

*page ==第幾頁(yè)

*showNum ==顯示幾頁(yè)

*/

function page($Str,$Page=0,$ShowNum=5){

$back = array();//返回?cái)?shù)據(jù)

$maxNum = 0;

if ($Str == "") {

$this->ER = "沒有數(shù)據(jù)";

return 0;

}

$this->queryResult = $this->query($Str);

if($this->queryResult){

if($Page==""){

$nopa=0;

}else{

$nopa = ($Page-1)*$ShowNum;

if ($nopanum_rows($this->queryResult);

$k=0;

$i=0;

$dd=$this->fetch_array($this->queryResult);

while($dd&&$nopa<=$maxnum&&$i= nopa="$maxNum;" this-="">queryResult,$nopa);

$row=$this->fetch_array($this->queryResult);

$nopa++;

$i++;

$back[] = $row;

if ($nopa >=$maxNum) {

break;

}

}

}

$this->pageNum = $maxNum;

return $back;

}

/**

*分頁(yè)的html頁(yè)碼

*/

function page_html($DataNum=0,$Page=1,$ShowNum=3,$web,$Post=''){

if ($DataNum == 0) {

$back = "沒有要查詢的數(shù)據(jù)";

}else {

if ($ShowNum<=0) {   $ShowNum = 3;   }   if ($Page<=0) {   $Page = 1;   }   if (empty($web)) {   $web = "#";   }   $pageNum = ceil($DataNum/$ShowNum);   if ($Page <= top="首頁(yè)<< " else="" if="" page="" uppage="上一頁(yè)">尾頁(yè)";

}else {

$foot = " >>尾頁(yè)";

}

$back = <

看完上述內(nèi)容,你們對(duì)PHP中怎么連接MSSQL有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

當(dāng)前文章:PHP中怎么連接MSSQL
轉(zhuǎn)載源于:http://chinadenli.net/article40/gidoho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、標(biāo)簽優(yōu)化、企業(yè)建站、品牌網(wǎng)站設(shè)計(jì)定制網(wǎng)站、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化