首頁 php教程 php手册 封装了ORACLE函数的数据库操作类

封装了ORACLE函数的数据库操作类

Jun 21, 2016 am 09:02 AM
connection db error function return

 

php // -*- C++ -*-
/*
* $Id: db-oci8.phl,v 1.2 1998/10/01
ssb Exp $
*/

$db_error_code = 0;
$db_error_msg = false;
$db_error_source = false;

/*
* Database specific notes:
*
* - You must configure Oracle listener to use this abstraction layer.
*
*/


/**
* @function db_connect
* @purpose Connect to a database
* @desc
* Connects to a database and returns and identifier for the connection.
* @arg database
* Data source name or database host to connect to.

* @arg user
* Name of user to connect as.

* @arg password
* The user's password.
*/
function db_connect($database, $user, $password)
{
$ret = @OCILogon($user, $password, $database);
db_check_errors($php_errormsg);
return $ret;
}

/*
* Function: db_query
* Arguments: $conn (int) - connection identifier
* $query (string) - SQL statement to execute
* Description: executes an SQL statement
* Returns: false - query failed
* integer - query succeeded, value is result handle
*/
function db_query($conn, $query)
{
$stmt = @OCIParse($conn, $query);
db_check_errors($php_errormsg);
if (!$stmt) {
return false;
}
if (@OCIExecute($stmt)) {
return $stmt;
}
db_check_errors($php_errormsg);
@OCIFreeStatement($stmt);
return false;
}

/*
* Function: db_fetch_row
* Arguments: $stmt (int) - result identifier
* Description: Returns an array containing data from a fetched row.
* Returns: false - error
* (array) - returned row, first column at index 0
*/
function db_fetch_row($stmt)
{
$cols = @OCIFetchInto($stmt, &$row);
if (!$cols) {
db_check_errors($php_errormsg);
return false;
}
return $row;
}

/*
* Function: db_free_result
* Arguments: $stmt (int) - result identifier
* Description: Frees all memory associated with a result identifier.
* Returns: false - failure
* true - success
*/
function db_free_result($stmt)
{
global $db_oci8_pieces;

if (isset($db_oci8_pieces[$stmt])) {
unset($db_oci8_pieces[$stmt]);
}
$ret = @OCIFreeStatement($stmt);
db_check_errors($php_errormsg);
return $ret;
}

/*
* Function: db_disconnect
* Arguments: $connection (int) - connection identifier
* Description: closes a database connection
* Returns: false - failure
* true - success
*/
function db_disconnect($connection)
{
$ret = @OCILogoff($connection);
db_check_errors($php_errormsg);
return $ret;
}

/*
* Function: db_autocommit
* Arguments: $connection (int) - connection identifier
* Description: turn autocommit on or off
* Returns: false - failure
* true - success
*/
function db_autocommit($connection, $enabled)
{
if (!$enabled) {
db_post_error(0, "Transactions not yet implemented");
return false;
}
return true;
}


function db_commit($connection)
{
return true;
}


function db_rollback($connection)
{
db_post_error(0, "Transactions not yet implemented");
return false;
}


function db_quote_string($string)
{
$ret = ereg_replace( "'", "''", $string);
return $ret;
}


function db_prepare($connection, $query)
{
global $db_oci8_pieces;

$pieces = explode( "?", $query);
$new_query = "";
$last_piece = sizeof($pieces) - 1;
print "br
>last_piece=$last_piece\n";
while (list($i, $piece) = each($pieces)) {
$new_query .= $piece;
if ($i last_piece) {
$new_query .= ":var$i";
}
}
print "br>new_query=$new_query\n";
$stmt = @OCIParse($connection, $new_query);
if (!$stmt) {
db_check_errors($php_errormsg);
return false;
}
for ($i = 0; $i last_piece; $i++) {
$bindvar = ":var$i";
print "br>trying to bind $bindvar\n";
if (!@OCIBindByName($stmt, $bindvar, &$db_oci8_pieces[$stmt][$i])) {
db_check_errors($php_errormsg);
@OCIFreeStatement($stmt);
return false;
}
}
return $stmt;
}


function db_execute($stmt, $data)
{
global $db_oci8_pieces;

while (list($i, $value) = each($data)) {
$db_oci8_pieces[$stmt][$i] = $data[$i];
}
$ret = @OCIExecute($stmt);
if (!$ret) {
db_check_errors($php_errormsg);
return false;
}
return true;
}


function db_error_code()
{
global $db_error_code;
return $db_error_code;
}


function db_error_msg()
{
global $db_error_msg;
return $db_error_msg;
}


function db_error_source()
{
global $db_error_source;
return $db_error_source;
}


function db_check_errors($errormsg)
{
global $db_error_code, $db_error_msg, $db_error_source;
if (ereg( '^([^:]*): (...-.....): (.*)', $errormsg, &$data)) {
list($foo, $function, $db_error_code, $db_error_msg) = $data;
$db_error_msg = "$function: $db_error_msg";
$db_error_source = "[Oracle][PHP][OCI8]";
} elseif (ereg( '^([^:]*): (.*)', $errormsg, &$data)) {
list($foo, $function, $db_error_msg) = $data;
$db_error_msg = "$function: $db_error_msg";
$db_error_code = 0;
$db_error_source = "[PHP][OCI8][db-oci8]";
} else {
$db_error_msg = $errormsg;
$db_error_code = 0;
$db_error_source = "[PHP][OCI8][db-oci8]";
}
}


function db_post_error($code, $message)
{
global $db_error_code, $db_error_msg, $db_error_source;
$db_error_code = $code;
$db_error_msg = $message;
$db_error_source = "[PHP][OCI8][db-oci8]";
}


function db_api_version()
{
return 10; // 1.0
}

?>

 



本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP Fatal error: Call to undefined method PDO::prepare() in的解決方法 PHP Fatal error: Call to undefined method PDO::prepare() in的解決方法 Jun 22, 2023 pm 06:40 PM

PHP作為一種流行的Web開發語言,已經被使用很久了。 PHP中整合的PDO(PHP資料物件)類別是我們在開發Web應用程式過程中與資料庫互動的常用方法。但是,一些PHP開發者經常遇到的問題是,當使用PDO類別與資料庫互動時,他們會收到這樣的錯誤:PHPFatalerror:CalltoundefinedmethodPDO::prep

在Vue應用程式中使用axios時出現「Uncaught (in promise) Error: Request failed with status code 500」怎麼辦? 在Vue應用程式中使用axios時出現「Uncaught (in promise) Error: Request failed with status code 500」怎麼辦? Jun 24, 2023 pm 05:33 PM

在Vue應用程式中使用axios是十分常見的,axios是一種基於Promise的HTTP客戶端,可以用於瀏覽器和Node.js。在開發過程中,有時會出現「Uncaught(inpromise)Error:Requestfailedwithstatuscode500」的錯誤提示,對於開發者來說,這個錯誤提示可能有些難以理解和解決。本文將會探討這

Oracle與DB2的SQL語法比較與區別 Oracle與DB2的SQL語法比較與區別 Mar 11, 2024 pm 12:09 PM

Oracle和DB2是兩個常用的關聯式資料庫管理系統,它們都有自己獨特的SQL語法和特性。本文將針對Oracle和DB2的SQL語法進行比較與區別,並提供具體的程式碼範例。資料庫連接在Oracle中,使用以下語句連接資料庫:CONNECTusername/password@database而在DB2中,連接資料庫的語句如下:CONNECTTOdataba

Oracle與DB2資料庫技術比較解析 Oracle與DB2資料庫技術比較解析 Mar 11, 2024 am 09:54 AM

Oracle和DB2是兩個知名的關聯式資料庫管理系統(RDBMS),在企業級應用中廣泛使用。在本文中,我們將對Oracle和DB2這兩種資料庫技術進行比較並進行詳細解析,包括其特點、效能、功能和使用範例等方面的分析。一、Oracle資料庫技術概述Oracle是由美國甲骨文公司開發的關係型資料庫管理系統。它被廣泛應用於企業級應用中,具有強大的性能、穩定性

0271:real time clock error開不開機怎麼辦 0271:real time clock error開不開機怎麼辦 Mar 13, 2023 am 11:30 AM

「0271:real time clock error」開不開機的解決方法:1、按一下F1,在出現的介面中,將選項列轉到第三個「Date/Time」;2、將系統時間手動修改成現在的時間;3、按F10,在彈出的對話框中,選擇yes;4、重新開啟筆記本即可正常開機。

解決C++程式碼中出現的「error: expected initializer before 'datatype'」問題 解決C++程式碼中出現的「error: expected initializer before 'datatype'」問題 Aug 25, 2023 pm 01:24 PM

解決C++程式碼中出現的「error:expectedinitializerbefore'datatype'」問題在C++程式設計中,有時我們在寫程式碼時會遇到一些編譯錯誤,其中一個常見的錯誤是「error:expectedinitializerbefore'datatype'」。這個錯誤通常在變數宣告或函數定義中發生,可能導致程式無法正確編譯或

解決C++程式碼中出現的「error: incomplete type is not allowed」問題 解決C++程式碼中出現的「error: incomplete type is not allowed」問題 Aug 26, 2023 pm 08:54 PM

解決C++程式碼中出現的「error:incompletetypeisnotallowed」問題在C++的程式設計過程中,有時會遇到一些編譯錯誤,其中一個常見的錯誤是「error:incompletetypeisnotallowed」。這個錯誤通常是由於在使用不完整的類型進行操作時引起的。本文將介紹這個錯誤的原因,並提供幾種解決方法。首先,我

C語言return的用法詳解 C語言return的用法詳解 Oct 07, 2023 am 10:58 AM

C語言return的用法有:1、對於傳回值類型為void的函數,可以使用return語句來提前結束函數的執行;2、對於傳回值型別不為void的函數,return語句的作用是將函數的執行結果傳回給呼叫者;3、提前結束函數的執行,在函數內部,我們可以使用return語句來提前結束函數的執行,即使函數並沒有回傳值。

See all articles