内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

怎么用PHP連接Oracle數(shù)據(jù)庫

這篇文章主要講解了“怎么用PHP連接Oracle數(shù)據(jù)庫”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用PHP連接Oracle數(shù)據(jù)庫”吧!

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供鹿泉網(wǎng)站建設(shè)、鹿泉做網(wǎng)站、鹿泉網(wǎng)站設(shè)計、鹿泉網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、鹿泉企業(yè)網(wǎng)站模板建站服務(wù),十年鹿泉做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

連接

< ?if($conn=Ora_Logon("user@TNSNAME","password"))   {echo"SUCCESS!Connectedtodatabase\n";   }else   {echo"Failed:-(Couldnotconnecttodatabase\n";}   Ora_Logoff($conn);   phpinfo();   ?>

以上代碼使用TNSNAME(在你的tnsnames.ora文件中指明)定義的Oracle數(shù)據(jù)庫名稱、用戶名稱和密碼連接數(shù)據(jù)庫。在成功連接的基礎(chǔ)上,ora_logon函數(shù)返回一個非零的連接ID并儲存在變量$conn中。

查詢

假設(shè)與數(shù)據(jù)庫已經(jīng)連接就緒,下面我們就來實際的應(yīng)用對數(shù)據(jù)庫的查詢。下面的代碼演示了一個連接并查詢的典型例子:

functionprintoraerr($in_cur)

{

//檢查Oracle是否出錯

//如果存在錯誤則顯示

//當(dāng)指針被激活時每次請求Oracle后調(diào)用該函數(shù)

if(ora_errorcode($in_cur))

echo"Oraclecode-".ora_error($in_cur)."\n";

return;

}

if(!($conn=ora_logon("user@TNSNAME","password")))

{echo"Connectiontodatabasefailed\n";

exit;

}

echo"Connectedasconnection-$conn\n";

echo"Openingcursor...\n";

$cursor=ora_open($conn);printoraerr($cursor);

echo"Openedcursor-$cursor\n";

$qry="selectuser,sysdatefromdual";

echo"Parsingthequery$qry...\n";

ora_parse($cursor,$qry,0);printoraerr($cursor);

echo"Queryparsed\n";

echo"Executingcursor...\n";

ora_exec($cursor);printoraerr($cursor);

echo"Executedcursor\n";

echo"Fetchingcursor...\n";

while(ora_fetch($cursor))

{

$user=ora_getcolumn($cursor,0);printoraerr($cursor);

$sysdate=ora_getcolumn($cursor,1);printoraerr($cursor);

echo"row=$user,$sysdate\n";

}

echo"Fetchedallrecords\n";

echo"Closingcursor...\n";

ora_close($cursor);

echo"Closedcursor\n";

echo"Loggingofffromoracle...\n";

ora_logoff($conn);

echo"Loggedofffromoracle\n";

?>

怎樣用PHP連接Oracle數(shù)據(jù)庫

顯示結(jié)果

以下代碼演示了怎樣查詢數(shù)據(jù)庫并將結(jié)果輸出:

functionprintoraerr($in_cur,$conn)

{

//檢查Oracle是否出錯

//如果存在錯誤則顯示

//當(dāng)指針被激活時每次請求Oracle后調(diào)用該函數(shù)

//Ifitencounteredanerror,weexitimmediately

if(ora_errorcode($in_cur))

{echo"Oraclecode-".ora_error($in_cur)."n";

ora_logoff($conn);

exit;

}

return;

}

functionexequery($w_qry,$conn)

{

$cursor=ora_open($conn);printoraerr($cursor,$conn);

ora_parse($cursor,$w_qry,0);printoraerr($cursor,$conn);

ora_exec($cursor);printoraerr($cursor,$conn);

$numrows=0;

$w_numcols=ora_numcols($cursor);

//顯示頭部

echo"\n";

for($i=0;$i<$w_numcols;$i++)   {   $align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";   echo"\t".ora_columnname($cursor,$i)."\n";   }   echo"\n";   while(ora_fetch($cursor))   {   echo"\n";   for($i=0;$i<$w_numcols;$i++) align="(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";" .="" else="" numrows="=0)" conn="ora_logon("user@SID","password")))" qry="SELECT   deptno\" from="" employee="">

基于HTTP的Oracle登錄

將以下代碼加在PHP頁面代碼之前以確認Oracle登錄。注意你必須正確設(shè)定$SID。

if(!isset($PHP_AUTH_USER))

{

Header("WWW-authenticate:basicrealm=\"$SID\"");

Header("HTTP/1.0401Unauthorized");

$title="LoginInstructions";

echo"

Youarenotauthorizedtoenterthesite

\n";

exit;

}

else

{

if(!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW)))

{Header("WWW-authenticate:basicrealm=\"$SID\"");

Header("HTTP/1.0401Unauthorized");

$title="LoginInstructions";

echo"

Youarenotauthorisedtoenterthesite

\n";

exit;

}}

?>

感謝各位的閱讀,以上就是“怎么用PHP連接Oracle數(shù)據(jù)庫”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么用PHP連接Oracle數(shù)據(jù)庫這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

標(biāo)題名稱:怎么用PHP連接Oracle數(shù)據(jù)庫
URL地址:http://www.rwnh.cn/article30/gdojpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站設(shè)計公司、靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、響應(yīng)式網(wǎng)站、域名注冊

廣告

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

成都定制網(wǎng)站網(wǎng)頁設(shè)計
晋州市| 绥中县| 循化| 德庆县| 昌都县| 安吉县| 沙坪坝区| 济阳县| 疏附县| 县级市| 遂宁市| 溧阳市| 海南省| 龙岩市| 陆丰市| 马尔康县| 瑞昌市| 连江县| 榆树市| 赤壁市| 赣榆县| 若羌县| 峨山| 若羌县| 小金县| 尖扎县| 集安市| 通许县| 东阳市| 岐山县| 浦北县| 远安县| 司法| 崇州市| 蒙山县| 阿荣旗| 辽阳市| 青神县| 上犹县| 新干县| 诏安县|