Oracle Database Access Object

Source: Internet
Author: User
Tags sql access oracle database
Access|object|oracle
Calling Example:
?
$conn = Ocilogon ("Www_cec", "Webchn99", "unicorn");
#or can just inclued file like "Include (" modcec_oci_conn.php3 ");"

$newOda = new ODA ($conn);
#################
#or can use Login to
# $newOda-=new ODA ();
# $newOda ("www", "->logon", "corn");
###############################################
$newOda->cmdstring= "Update test set nouse= ' DFS ' where login_name= ' Guoyafeng '";
if (! $newOda->execute ()) {
Echo $newOda->err;
}
Else
{
Echo $newOda->rows; #get the affected row number.
}
#or can call execute like this####
/*
$newOda->execute ("Update test set nouse= ' DFS ' where login_name= ' Guoyafeng '");
*/
#############################

#the following demostrate the Open method.
$newOda->open ("SELECT * from Test")) or $newOda->err;

#Get data from RS
echo "Count is". $newOda->rows;
For ($i =0 $i < $newOda->rows; $i + +)
For ($j =0 $j < $newOda->cols; $j + +)
{
echo $newOda->rs[$i] [$j];

}


$newOda->logoff ();
?>
?
/********************************************************************************#
# File NAME:ODA.PHP3 #
# Author:guo Yafeng #
# function:oracle DB Access. #
# Maint History: #
# Sept 18,2000. #
#                                                                                #
#                                                                                #
#********************************************************************************/


/********************************************************************************#
#Object Interface Description: #
# Properties: #
# conn Connection Object #
# err_no Error No #
# Err Error Description #
# cmdstring SQL statements to execute. #
# rows affected rows. #
# RS return value array.
# Cols #
#                                                                                #
# Method: #
# Open Execute the cmdstring and return value #
# Execute execute the cmdstring. #
#********************************************************************************/

file://$conn = Ocilogon ("Www_ce", "Ceonline99", "WSGP");
$conn = Ocilogon ("Www_cec", "Webchn99", "unicorn");
if ($SERVER _name = "")
$SERVER _name = $HTTP _host;

Class ODA
{




function ODA ($CN = "") {

if ($CN!= "")
$this->conn= $CN;
return TRUE;

}

function Logon ($user, $pass, $db) {

if (!) ( $this->conn = Ocilogon ($user, $pass, $db))) {

$this->err_no=106;
$this->err= "Error 106:failed to logon."
return FALSE;
};

return TRUE;

}
function Open ($sql = "") file://$this->cmdstring
{
if ($this->conn== "") {
$this->err_no=100;
$this->err= "Error 100,connection Object Required."
return FALSE;
}

if ($sql = = "" and $this->cmdstring== "") {
$this->err_no=101;
$this->err= "Error 101,sql Statement Required."
return FALSE;
}
if ($sql = = "")
$sql = $this->cmdstring;
if (!) ( $cursor =ociparse ($this->conn, $sql))) {
$this->err_no=102;
$this->err= "Server Internal error:failed to parse SQL Statement.";
return FALSE;
}

if (! Ociexecute ($cursor)) {
$this->err_no=103;
$this->err= "Server Internal error:failed to execute SQL Statement.";
return FALSE;
}
$this->rows=0;
while (Ocifetchinto ($cursor, $this->rs[$this->rows])) {

$this->rows++;

}
$this->cols=ocinumcols ($cursor);

if ($this->rows==0) {

$this->err_no=104;
$this->err= "Warning:no rows affectted. RS result are not available. ";
}

Ocifreestatement ($cursor);

return TRUE;
}


function Execute ($sql = "") {
if ($this->conn== "") {
$this->err_no=100;
$this->err= "Error 100,connection Object Required."
return FALSE;
}

if ($sql = = "" and $this->cmdstring== "") {
$this->err_no=101;
$this->err= "Error 101,sql Statement Required."
return FALSE;
}
if ($sql = = "")
$sql = $this->cmdstring;

if (!) ( $cursor =ociparse ($this->conn, $sql))) {
$this->err_no=102;
$this->err= "Server Internal error:failed to parse SQL Statement.";
return FALSE;
}


if (! Ociexecute ($cursor)) {
$this->err_no=103;
$this->err= "Server Internal error:failed to execute SQL Statement.";
return FALSE;
}
$this->rows=ocirowcount ($cursor);
Ocifreestatement ($cursor);

return TRUE;
}
function LogOff () {

if (! Ocilogoff ($conn)) {

$this->err_no=105;
$this->err= "Server Internal error:failed to logoff database."
return FALSE;
}
return TRUE;

}
}
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.