国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

封裝了ORACLE函數的數據庫操作類

2024-08-29 13:32:40
字體:
來源:轉載
供稿:網友

 

<?php // -*- c++ -*-
/*
* $id: db-oci8.phl,v 1.2 1998/10/01
19:16:06 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 ([email protected]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
}

?>

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁晋县| 谢通门县| 开平市| 高唐县| 余江县| 奈曼旗| 盐亭县| 开鲁县| 罗甸县| 廊坊市| 英超| 桦南县| 榆社县| 隆德县| 西林县| 梨树县| 将乐县| 翼城县| 南开区| 惠来县| 微博| 广水市| 工布江达县| 三穗县| 临猗县| 阿克| 长白| 科尔| 江达县| 延长县| 塔城市| 巴楚县| 云安县| 南投市| 饶平县| 乐亭县| 昔阳县| 高台县| 营口市| 广河县| 祁连县|