if ($conn=Ora_Logon("user@TNSNAME","password")) { echo "SUCCESS ! Connected to databasen"; } else { echo "Failed :-( Could not connect to databasen"; } Ora_Logoff($conn); phpinfo(); ?> 以上代碼使用TNSNAME(在你的tnsnames.ora檔案中指明)定義的Oracle資料庫名稱、使用者名稱稱和密碼串連資料庫。在成功串連的基礎上,ora_logon函數返回一個非零的串連ID並儲存在變數$conn中。
// 主程式 if(!($conn=ora_logon("user@SID","password"))) { echo "Error: Cannot connect to databasen"; exit; } $qry="SELECT deptno "Dept" ,empno "Emp" ,empnm "Name" ,salary "Salary" FROM employee ORDER BY 1,2"; exequery($qry); ora_logoff($conn); ?> (譯者註:以上程式碼片段缺少注釋,請讀者參考PHP Manual的Oracle資料庫函數部分)
11.4 基於HTTP的Oracle登入
將以下代碼加在PHP頁面代碼之前以確認Oracle登入。注意你必須正確設定$ SID。 if(!isset($PHP_AUTH_USER)) { Header("WWW-authenticate: basic realm="$SID""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; echo "<blockquote> You are not authorized to enter the site blockquote> n"; exit; } else { if (!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW))) { Header("WWW-authenticate: basic realm="$SID""); Header("HTTP/1.0 401 Unauthorized"); $title="Login Instructions"; echo "<blockquote> You are not authorised to enter the site blockquote> n"; exit; } } ?>