php教程串連oracle資料庫教程代碼
$conn = OCILogon("scott","tiger","你的oracle資料庫名字");
$stmt = OCIParse($conn,"select empno, ename from emp");
/* 使用 OCIDefineByName 要在執行 OCIExecute 前 */
OCIDefineByName($stmt,"EMPNO",&$empno);
OCIDefineByName($stmt,"ENAME",&$ename);
OCIExecute($stmt);
while (OCIFetch($stmt)) {
echo "empno:".$empno."n";
echo "ename:".$ename."n";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
/*
註明:
php預設狀態下是不能與oracle資料庫連接的,我們得 在php.ini的Windows Extensions段修改成
extension_dir = "所要載入的dll的檔案路徑" (如c:phpextensions)
extension=php_oci8.dll
extension=php_oracle.dll
第二步:
iis中設定isapi
*/
//二
if ($conn=Ora_Logon("user@TNSNAME","password"))
{
echo "SUCCESS ! Connected to databasen";
}
else
{
echo "Failed :-( Could not connect to databasen";
}
Ora_Logoff($conn);
//串連資料庫執行個體三
$connection = Ora_Logon ("webmaster@111cn.net", "123");
if ($connection == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."";
exit;
}
$cursor = Ora_Open ($connection);
if ($cursor == false){
echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."";
exit;
}
Ora_Commit ($connection);
Ora_Close ($cursor);
Ora_Logoff ($connection);
/*
說明函數功能:
integer ora_logon(string user , string password)根據指定使用者串連oracle資料庫伺服器
integer ora_open(integer connection)給出的串連上執行查詢。PHP產生一個指標,解析查詢
integer ora_do(integer connection, string query)為查詢並準備好執行
integer ora_parse(integer cursor, string query)ora_parse函數解析過的查詢。