Home 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
}

?>

 



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Jun 22, 2023 pm 06:40 PM

PHP is a popular web development language that has been used for a long time. The PDO (PHP Data Object) class integrated in PHP is a common way for us to interact with the database during the development of web applications. However, a problem that some PHP developers often encounter is that when using the PDO class to interact with the database, they receive an error like this: PHPFatalerror:CalltoundefinedmethodPDO::prep

Solve the problem of 'error: incomplete type is not allowed' in C++ code Solve the problem of 'error: incomplete type is not allowed' in C++ code Aug 26, 2023 pm 08:54 PM

Solve the "error:incompletetypeisnotallowed" problem in C++ code. During the C++ programming process, you sometimes encounter some compilation errors. One of the common errors is "error:incompletetypeisnotallowed". This error is usually caused by operating on an incomplete type. This article will explain the cause of this error and provide several solutions. firstly, I

What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? Jun 24, 2023 pm 05:33 PM

It is very common to use axios in Vue applications. axios is a Promise-based HTTP client that can be used in browsers and Node.js. During the development process, the error message "Uncaught(inpromise)Error: Requestfailedwithstatuscode500" sometimes appears. For developers, this error message may be difficult to understand and solve. This article will explore this

Comparative analysis of Oracle and DB2 database technology Comparative analysis of Oracle and DB2 database technology Mar 11, 2024 am 09:54 AM

Oracle and DB2 are two well-known relational database management systems (RDBMS) that are widely used in enterprise applications. In this article, we will compare the two database technologies of Oracle and DB2 and analyze them in detail, including analysis of their characteristics, performance, functions and usage examples. 1. Overview of Oracle database technology Oracle is a relational database management system developed by Oracle Corporation of the United States. It is widely used in enterprise-level applications and has strong performance and stability.

Comparison and differences of SQL syntax between Oracle and DB2 Comparison and differences of SQL syntax between Oracle and DB2 Mar 11, 2024 pm 12:09 PM

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

0271: What should I do if the computer cannot be turned on due to real time clock error? 0271: What should I do if the computer cannot be turned on due to real time clock error? Mar 13, 2023 am 11:30 AM

Solution to "0271: real time clock error" that cannot boot: 1. Press F1, and in the interface that appears, move the option bar to the third item "Date/Time"; 2. Manually change the system time to the current one time; 3. Press F10 and select yes in the pop-up dialog box; 4. Re-open the notebook to boot normally.

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Solve the 'error: expected initializer before 'datatype'' problem in C++ code Solve the 'error: expected initializer before 'datatype'' problem in C++ code Aug 25, 2023 pm 01:24 PM

Solve the "error:expectedinitializerbefore'datatype'" problem in C++ code. In C++ programming, sometimes we encounter some compilation errors when writing code. One of the common errors is "error:expectedinitializerbefore'datatype'". This error usually occurs in a variable declaration or function definition and may cause the program to fail to compile correctly or

See all articles