通過PHP你可以輕松的連接到數據庫
PHP提供了兩套函數與Oracle連接
連接
< ? if ($conn=Ora_Logon(
{ echo
}else
{echo
Ora_Logoff($conn);
phpinfo();
?>
以上代碼使用TNSNAME(在你的tnsnames
查詢
假設與數據庫已經連接就緒
function printoraerr($in_cur)
{
// 檢查Oracle是否出錯
// 如果存在錯誤則顯示
// 當指針被激活時每次請求Oracle後調用該函數
if(ora_errorcode($in_cur))
echo
return;
}
if (!($conn=ora_logon(
{echo
exit;
}
echo
echo
$cursor=ora_open($conn); printoraerr($cursor);
echo
$qry=
echo
ora_parse($cursor
echo
echo
ora_exec($cursor); printoraerr($cursor);
echo
echo
while(ora_fetch($cursor))
{
$user=ora_getcolumn($cursor
$sysdate=ora_getcolumn($cursor
echo
}
echo
echo
ora_close($cursor);
echo
echo
ora_logoff($conn);
echo
?>
顯示結果
以下代碼演示了怎樣查詢數據庫並將結果輸出
function printoraerr($in_cur
{
// 檢查Oracle是否出錯
// 如果存在錯誤則顯示
// 當指針被激活時每次請求Oracle後調用該函數
// If it encountered an error
if(ora_errorcode($in_cur))
{echo
ora_logoff($conn);
exit;
}
return;
}
function exequery($w_qry
{
$cursor=ora_open($conn); printoraerr($cursor
ora_parse($cursor
ora_exec($cursor); printoraerr($cursor
$numrows=
$w_numcols=ora_numcols($cursor);
// 顯示頭部
echo
for ($i=
{
$align=(ora_columntype($cursor
echo
}
echo
while(ora_fetch($cursor))
{
echo
for ($i=
{
$align=(ora_columntype($cursor
if(ora_columntype($cursor
echo
ora_getcolumn($cursor
else
echo
printoraerr($cursor
}
$numrows++;
echo
}
if ($numrows==
echo
else
{
echo
echo
echo
echo
}
echo
ora_close($cursor);
return;
}
// 主程序
if(!($conn=ora_logon(
{
echo
exit;
}
$qry=
deptno \
FROM
employee
ORDER BY
exequery($qry);
ora_logoff($conn);
?>
基於HTTP的Oracle登錄
將以下代碼加在PHP頁面代碼之前以確認Oracle登錄
if(!isset($PHP_AUTH_USER))
{
Header(
Header(
$title=
echo
You are not authorized to enter the site
\n
exit;
}
else
{
if (!($conn=ora_logon(
{Header(
Header(
$title=
echo
You are not authorised to enter the site
\n
exit;
}}
?>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25865.html