"Warning": Do not modify without permission
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
//
"File name": C_ora_db.inc
"Action": Oracle Common Function Class
"Author": Tian Ash
//
"Last Modified Date": 2001/05/11[cxx]
"Variable definition rule": ' c_ ' = character type, ' i_ ' = integer, ' n_ ' = numeric, ' L_ ' = boolean, ' a_ ' = array type
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
※db_logon () Open database connection
※db_query () General Select
※db_change () General function for database changes (insert,delete,update)
※db_insert () Insert, call Db_change () directly
※db_delete () Delete, call Db_change () directly
※db_update () Update, call Db_change () directly
※db_commit () Transaction submission
※db_rollback () transaction fallback
※db_logoff () Disconnecting database connections
//------------------------------------------------------------------------------------------
Class c_ora_db
{
//------------------------------------------------------------------------------------------
Variable definition
//------------------------------------------------------------------------------------------
var $C _user = ""; Database user Name
var $C _passwd = ""; Database Password
var $C _db = ""; Database name
var $I _linkid = 0; Connection handle
var $I _stmtid = 0; Query handle
var $color = ""; Global color
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_logon ()
Role: Open the database connection
Parameters: None
Return value: Line handle (integer type)
Remark: None
//------------------------------------------------------------------------------------------
function Db_logon ()
{
$this->i_linkid = @OCILogon ($this->c_user, $this->c_passwd, $this->c_db);
if ($this->i_linkid = = 0) {alertexit (' database link failed, please contact DBA! ');}
return $this->i_linkid;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_query ($C _sql, $A _define= "", $I _start=-1, $I _end=-1)
Role: SELECT
Parameter: $C _sql SQL statement
$A _define The fields to be bound. Array type
$I _start starts fetching records-1 takes out all the records of the query
$I _end end of record
Return value: Two-dimensional array ($A _rs)
Remark: by digital 0,1,2 .... The value of the corresponding field can be accessed; Or you can access the value of the corresponding field by querying the field name
The first record can be accessed by $a_rs[0][0] or $a_rs[0][' name '] or $a_rs[0][' name '). Name field
$I _start, $I _end is a parameter that is used with paging.
//------------------------------------------------------------------------------------------
function Db_query ($C _sql, $A _define= "", $I _start=-1, $I _end=-1)
{
if (! $C _sql) {alertexit ("parameter not complete! ");} Check parameters
Connection detection
if ($this->i_linkid = = 0) {alertexit (' database link failed, please contact DBA! ');}
Format detection
$this-I_stmtid = Ociparse ($this, I_linkid, $C _sql);
if (! $this-I_stmtid) {alertexit (' SQL format Error! Please contact the programmer ');}
If no bound field is specified, the SQL statement is taken from the
if ($A _define== "")
{
$A _cur = Explode ("Select", $C _sql);
$A _cur = Explode ("from", $A _cur[1]);
$A _define = Explode (",", $A _cur[0]);
}
Binding a database table field
if (GetType ($A _define) = = "Array")//Query column is an array
{
for ($i =0; $i {
$A _define_up[$i] = Trim (Strtoupper ($A _define[$i)); Capitalize and remove spaces
}
for ($i =0; $i {
Ocidefinebyname ($this-I_stmtid, "$A _define_up[$i]", &$ $A _define[$i]); Binding
}
}
ElseIf (Trim ($A _define) <> "")//Query column only one
{
$A _define_up = Trim (Strtoupper ($A _define));
Ocidefinebyname ($this, I_stmtid, "$A _define_up", &$ $A _define);
}
Execute a well-bound SQL statement
if (! Ociexecute ($this-I_stmtid))
{
echo "
Execution Error:SQL Error: $C _sql
";
return false;
}
$lower = 0; Returns the first-dimensional subscript control variable for a two-dimensional array
$cnt = 0; Starting to take a number label
Fetch Records
while (Ocifetchinto ($this-i_stmtid,& $cur, OCI_ASSOC))
{
Fetch all the records from the query
if ($I _start = =-1)
{
if (GetType ($A _define) = = "Array")//Query column is an array
{
for ($i =0; $i {
if ($cur [$A _define_up[$i]] <> $ $A _define[$i])
{
$ $A _define[$i] = $cur [$A _define_up[$i]];
}
$A _rs[$lower] [$i] = $ $A _define[$i]; Using Digital Access
$A _rs[$lower] [$A _define[$i]] = $ $A _define[$i]; With smaller access
$A _rs[$lower] [$A _define_up[$i]] = $ $A _define[$i]; Access in uppercase
}
}
ElseIf (Trim ($A _define) <> "")//Query column only one
{
if ($cur [$A _define_up] <> $ $A _define)
{
$ $A _define = $cur [$A _define_up];
}
$A _rs[$lower][0] = $ $A _define; Using Digital Access
$A _rs[$lower] [$A _define] = $ $A _define; Access in lowercase
$A _rs[$lower] [$A _define_up] = $ $A _define; Use larger access
}
$lower + +; Subscript Plus One
}
Remove the specified record (with paging)
if ($I _start <>-1)
{
if ($cnt >= $I _start)
{
$cnt + +;
if ($I _end-$I _start <> 0)
{
$I _end--;
if (GetType ($A _define) = = "Array")
{
for ($i =0; $i {
if ($cur [$A _define_up[$i]] <> $ $A _define[$i])
{
$ $A _define[$i] = $cur [$A _define_up[$i]];
}
$A _rs[$lower] [$i] = $ $A _define[$i]; Using Digital Access
$A _rs[$lower] [$A _define[$i]] = $ $A _define[$i]; With smaller access
$A _rs[$lower] [$A _define_up[$i]] = $ $A _define[$i]; Access in uppercase
}
}elseif (Trim ($A _define) <> "")
{
if ($cur [$A _define_up] <> $ $A _define)
{
$ $A _define = $cur [$A _define_up];
}
$A _rs[$lower][0] = $ $A _define; Using Digital Access
$A _rs[$lower] [$A _define] = $ $A _define; With smaller access
$A _rs[$lower] [$A _define_up] = $ $A _define; Access in uppercase
}
$lower + +;
}else
{
Break If $i_end-$I _start=0 means to take the record and jump out of the while loop
}
}else
{
$cnt + +; If $cnt< $I _start, $cnt + +
}
}
} The end of//while
Disposes the handle and returns the query data (a two-dimensional array)
Ocifreestatement ($this-I_stmtid);
return $A _rs;
} The end of//function
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_change ($C _sql, $A _bind)
Function: DB change
Parameter: $C _sql SQL statement
$A _bind The fields to be bound. Array type
Return Value: Boolean value
Remark: Insert,delete,update Universal
//------------------------------------------------------------------------------------------
function Db_change ($C _sql, $A _bind= "")
{
if (! $C _sql) {alertexit ("parameter not complete! ");} Check parameters
Connection detection
if ($this, i_linkid== "") {Alertexit ("Our database is busy, please connect again later!") ");}
Format detection
$this-I_stmtid = Ociparse ($this, I_linkid, $C _sql);
if (! $this-I_stmtid) {alertexit (' SQL format Error! Please contact the programmer ');}
Binding
if (GetType ($A _bind) = = "Array")
{
for ($i =0; $i {
Global $ $A _bind[$i];
$ $A _bind[$i] = stripslashes ($ $A _bind[$i]); Remove backslash characters
$ $A _bind[$i] = Str_replace (" }
for ($i =0; $i Ocibindbyname ($this, I_stmtid, ": $A _bind[$i]", &$ $A _bind[$i],-1); Binding
}
}
ElseIf (Trim ($A _bind) <> "")//is not an array, is a character
{
Global $ $A _bind;
$ $A _bind = stripslashes ($ $A _bind);
$ $A _bind = Str_replace (" Ocibindbyname ($this, I_stmtid, ": $arrBind", &$ $A _bind,-1);
}
Execute and Detect success
if (! Ociexecute ($this-I_stmtid,oci_default))
{
echo "
Execution Error:SQL Error: $C _sql
";
return false;
}
/*//returns the number of rows affected
Global $I _changenum;
$I _changenum = ocinumrows ($this, I_stmtid); * *
Release handle, return value
Ocifreestatement ($this-I_stmtid);
return true;
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_delete ($C _sql)
Role: Delete
Parameter: C_sql SQL statement
Return Value: Boolean value
Note: This function is just for intuitive use, essentially calling Db_change ()
//------------------------------------------------------------------------------------------
function Db_delete ($C _sql)
{
return $this Db_change ($C _sql);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_insert ($C _sql,a_bind)
Role: Insert
Parameter: C_sql SQL statement
A_bind binding
Return Value: Boolean value
Note: This function is just for intuitive use, essentially calling Db_change ()
//------------------------------------------------------------------------------------------
function Db_insert ($C _sql, $A _bind= "")
{
return $this Db_change ($C _sql, $A _bind);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: db_update ($C _sql,a_bind)
Role: Update
Parameter: C_sql SQL statement
A_bind binding
Return Value: Boolean value
Note: This function is just for intuitive use, essentially calling Db_change ()
//------------------------------------------------------------------------------------------
function Db_update ($C _sql, $A _bind= "")
{
return $this Db_change ($C _sql, $A _bind);
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_commit ()
Role: Transaction Submission
Parameters: None
Return Value: Boolean value
Remark: None
//------------------------------------------------------------------------------------------
function Db_commit ()
{
Return (Ocicommit ($this->i_linkid));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_rollback ()
Role: Transaction fallback
Parameters: None
Return Value: Boolean value
Remark: None
//------------------------------------------------------------------------------------------
function Db_rollback ()
{
Return (Ocirollback ($this->i_linkid));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
Function name: Db_logoff ()
Role: Disconnecting database connections
Parameters: None
Return Value: Boolean value
Remark: None
//------------------------------------------------------------------------------------------
function Db_logoff ()
{
Return (Ocilogoff ($this->i_linkid));
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
}
?>
http://www.bkjia.com/PHPjc/315288.html www.bkjia.com true http://www.bkjia.com/PHPjc/315288.html techarticle ?//"Warning": Do not modify/--------------------------------------------------------------------------------------without permission ---- //--------------------------------------...