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

 

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脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。