jrthor2
12-16-2003, 08:53 AM
Our site uses a dbconn.php file that has our database calls in it so that we just include this file when connecting to our Oracle database. I need to swithc this to using odbc, can someone please help? My dbconn.php file is below:
<? // common header to be included in all files--if we've already
// included this filename, don't include it again
$me=ereg("/", __FILE__) ? substr(strrchr(__FILE__,"/"),1) : __FILE__;
if ( !($$me)) {
$$me=1;
define("DELIM", "0xA9");
class mydb
{ //CLASS DEFN. for mydb to make selects easy...and quiet
// USAGE: (1)
// include ("dbconn.php");
// $conn = new mydb;
// $conn->my_conn();
// $sel_stmt = "Select something from somewhere...";
// $conn->my_stmt($sel_stmt);
// for ($i=0;$i < $conn->numrows;$i++)
// {
// print $conn->results["SOMECOLUMNNAME1"][$i];
// print ", ";
// print $conn->results["SOMECOLUMNNAME2"][$i];
// }
// $conn->my_close();
// (2)
// include ("dbconn.php");
// $conn = new mydb;
// $sel_stmt = "Select something from somewhere...";
// $conn->my_sel($sel_stmt);
// for (.....refer to above)
//
// (3) (my_sqlbnd)
// $sql_stmt = "select * from ineml_route where email_id like
// :email";
// $email="seand%";
// $conn = new mydb;
// $strarg = "email" . DELIM . $email;
// $conn->my_sqlbnd($sql_stmt, $strarg);
// print "RETURN: " . $conn->ORA_ERR . " DESC: " . $conn->ORA_ERR_DESC . "\n";
// print "Numrows: " . $conn->numrows . "\n";
// for ($i=0;$i < $conn->numrows;$i++)
// {
// print $conn->results["CAT_ID"][$i];
// print ", ";
// print $conn->results["EMAIL_ID"][$i];
// print "<br>\n";
// }
//
//
//
//
// **note no my_close is needed b/c my_sel does it all.
var $c; // new connection to mysql db
var $querystr; //string containing query passed in
var $sqlstmt; //database object created as result of query
var $results; //Results array resulting from any query
var $numrows; //Number of rows affected from query
var $row; //Row Object containg column values of query
var $i; //Current row pointer
var $ORA_ERR; //Oracle Error Code
var $ORA_ERR_DESC; //Oracle Error Desc.
function my_conn()
{ //Create database connection using bg-id
global $my_db_userid, $my_db_passwd, $my_db_instance;
error_reporting(0);
$this->i = 0;
$this->c = @OCILogon ($my_db_userid, $my_db_passwd, $my_db_instance) or
$this->_handle_connection_failure();
error_reporting(7);
}
function _handle_connection_failure()
{
$docroot=$_SERVER["DOCUMENT_ROOT"];
$document="$docroot/home/database_error.php";
include_once($document);
exit;
}
function my_err()
{
$err = OCIError($this->sqlstmt);
$this->ORA_ERR = $err["code"];
$this->ORA_ERR_DESC = $err["message"];
}
function my_sqlbnd()
{ //Execute bind and sqlstatement, dynamic args. (SQL, VARNAME, VARVALUE, ...)
error_reporting(0);
$this->my_conn();
$stmt = func_get_arg (0);
$this->sqlstmt = @OCIparse($this->c, $stmt);
#$numargs = func_num_args();
$strarg = func_get_arg(1);
$this->querystr="$stmt (args=>$strarg<=";
#print "Array string in is: " . $strarg;
$args = split(DELIM, $strarg);
$numargs = count($args);
#print "Array count is: " . $numargs;
if ((($numargs) % 2) <> 0)
{
print "Sorry, invalid # arguments: " . $i . "\n";
}
else
{
for ($i=0;$i<$numargs;$i+=2)
{ // Get each BIND ARGUMENT and BIND it.
$argnme = $args[$i];
$k = $i + 1;
// Dynamically create arguement variable and assign value
$$argnme = $args[$k];
#print "argnme is: " . $argnme . " value is: (" . $arg[$k] . ")\n";
$bindval = ":" . $argnme;
//
// The ORACLE error below means you didn't pass SQL with
// BIND variables that matched your ARGUEMENTS
// OCIBindByName: ORA-01036: illegal variable name
//
@OCIBindByName($this->sqlstmt,$bindval,&$$argnme,-1);
}
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
$this->my_close();
} // end if not enough ARGS
error_reporting(7);
}
function my_sel($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->querystr=$stmt;
$this->my_conn();
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = @OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
$this->my_close();
error_reporting(7);
}
function my_upd($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->my_conn();
$this->querystr=$stmt;
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
$this->numrows = OCIRowCount($this->sqlstmt);
if ( eregi('insert', $stmt))
{
if (( $this->numrows == 0 ) && ( $this->ORA_ERR == 1 ))
{
print "Insert failed! Try an UPDATE! \n";
}
}
$this->my_close();
error_reporting(7);
}
function my_stmt($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->querystr=$stmt;
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = @OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
error_reporting(7);
}
function my_close()
{ //Close mysql connection
error_reporting(0);
@OCIFreeStatement($this->sqlstmt);
@OCILogoff($this->c);
error_reporting(7);
}
}//end of class
} //end of ifdef statement
?>
<? // common header to be included in all files--if we've already
// included this filename, don't include it again
$me=ereg("/", __FILE__) ? substr(strrchr(__FILE__,"/"),1) : __FILE__;
if ( !($$me)) {
$$me=1;
define("DELIM", "0xA9");
class mydb
{ //CLASS DEFN. for mydb to make selects easy...and quiet
// USAGE: (1)
// include ("dbconn.php");
// $conn = new mydb;
// $conn->my_conn();
// $sel_stmt = "Select something from somewhere...";
// $conn->my_stmt($sel_stmt);
// for ($i=0;$i < $conn->numrows;$i++)
// {
// print $conn->results["SOMECOLUMNNAME1"][$i];
// print ", ";
// print $conn->results["SOMECOLUMNNAME2"][$i];
// }
// $conn->my_close();
// (2)
// include ("dbconn.php");
// $conn = new mydb;
// $sel_stmt = "Select something from somewhere...";
// $conn->my_sel($sel_stmt);
// for (.....refer to above)
//
// (3) (my_sqlbnd)
// $sql_stmt = "select * from ineml_route where email_id like
// :email";
// $email="seand%";
// $conn = new mydb;
// $strarg = "email" . DELIM . $email;
// $conn->my_sqlbnd($sql_stmt, $strarg);
// print "RETURN: " . $conn->ORA_ERR . " DESC: " . $conn->ORA_ERR_DESC . "\n";
// print "Numrows: " . $conn->numrows . "\n";
// for ($i=0;$i < $conn->numrows;$i++)
// {
// print $conn->results["CAT_ID"][$i];
// print ", ";
// print $conn->results["EMAIL_ID"][$i];
// print "<br>\n";
// }
//
//
//
//
// **note no my_close is needed b/c my_sel does it all.
var $c; // new connection to mysql db
var $querystr; //string containing query passed in
var $sqlstmt; //database object created as result of query
var $results; //Results array resulting from any query
var $numrows; //Number of rows affected from query
var $row; //Row Object containg column values of query
var $i; //Current row pointer
var $ORA_ERR; //Oracle Error Code
var $ORA_ERR_DESC; //Oracle Error Desc.
function my_conn()
{ //Create database connection using bg-id
global $my_db_userid, $my_db_passwd, $my_db_instance;
error_reporting(0);
$this->i = 0;
$this->c = @OCILogon ($my_db_userid, $my_db_passwd, $my_db_instance) or
$this->_handle_connection_failure();
error_reporting(7);
}
function _handle_connection_failure()
{
$docroot=$_SERVER["DOCUMENT_ROOT"];
$document="$docroot/home/database_error.php";
include_once($document);
exit;
}
function my_err()
{
$err = OCIError($this->sqlstmt);
$this->ORA_ERR = $err["code"];
$this->ORA_ERR_DESC = $err["message"];
}
function my_sqlbnd()
{ //Execute bind and sqlstatement, dynamic args. (SQL, VARNAME, VARVALUE, ...)
error_reporting(0);
$this->my_conn();
$stmt = func_get_arg (0);
$this->sqlstmt = @OCIparse($this->c, $stmt);
#$numargs = func_num_args();
$strarg = func_get_arg(1);
$this->querystr="$stmt (args=>$strarg<=";
#print "Array string in is: " . $strarg;
$args = split(DELIM, $strarg);
$numargs = count($args);
#print "Array count is: " . $numargs;
if ((($numargs) % 2) <> 0)
{
print "Sorry, invalid # arguments: " . $i . "\n";
}
else
{
for ($i=0;$i<$numargs;$i+=2)
{ // Get each BIND ARGUMENT and BIND it.
$argnme = $args[$i];
$k = $i + 1;
// Dynamically create arguement variable and assign value
$$argnme = $args[$k];
#print "argnme is: " . $argnme . " value is: (" . $arg[$k] . ")\n";
$bindval = ":" . $argnme;
//
// The ORACLE error below means you didn't pass SQL with
// BIND variables that matched your ARGUEMENTS
// OCIBindByName: ORA-01036: illegal variable name
//
@OCIBindByName($this->sqlstmt,$bindval,&$$argnme,-1);
}
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
$this->my_close();
} // end if not enough ARGS
error_reporting(7);
}
function my_sel($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->querystr=$stmt;
$this->my_conn();
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = @OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
$this->my_close();
error_reporting(7);
}
function my_upd($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->my_conn();
$this->querystr=$stmt;
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
$this->numrows = OCIRowCount($this->sqlstmt);
if ( eregi('insert', $stmt))
{
if (( $this->numrows == 0 ) && ( $this->ORA_ERR == 1 ))
{
print "Insert failed! Try an UPDATE! \n";
}
}
$this->my_close();
error_reporting(7);
}
function my_stmt($stmt)
{ //Execute passed in SQL and Return $results
error_reporting(0);
$this->querystr=$stmt;
$this->sqlstmt = @OCIparse($this->c, $stmt);
@OCIexecute($this->sqlstmt);
$this->my_err();
if ( eregi('select', $stmt))
{
$this->numrows = @OCIFetchStatement ($this->sqlstmt, $this->results);
}
else
{
$this->numrows = OCIRowCount($this->sqlstmt);
}
error_reporting(7);
}
function my_close()
{ //Close mysql connection
error_reporting(0);
@OCIFreeStatement($this->sqlstmt);
@OCILogoff($this->c);
error_reporting(7);
}
}//end of class
} //end of ifdef statement
?>