What I'm trying to do:
Code: Select all
<?php
/* CONNECT TO DB*/
$MSC = new mysqlConnection(DB1,LEVEL_READ_INSERT_DELETE);
/* RUN QUERY */
$qry = "INSERT INTO TABLENAME(VAL1,VAL2) VALUES('$someVar',$somevar2) WHERE ID=$xyz";
$result = @mysql_query($qry);
if(!$result){ //AN ERROR OCCURED, INSERT LOG INTO ERROR TABLE
insertErrorIn_Error_Log(ERROR_ID_1,$qry);
}
$qry = "SELECT * FROM TABLE2 WHERE ID=$xyz";
...
..
.
?>Code: Select all
<?php
function insertErrorIn_Error_Log($error_id,$qry){
$MSC = new mysqlConnection(DB2,LEVEL_INSERT);
$qry = "INSERT INTO ERROR_TABLE($error_id,'$qry')";
@mysql_query($qry);
//SET CONNECTION BACK TO ORIGINAL CONNECTION
??????????
/* In order for the code to keep working, I need to re-connect
back to the original database. Below are some example I’ve tried;
I'm just not satisfied with the functionality. */
}
?>Code: Select all
<?php
/* The database connection class accepts two predefined constants. The first parameter identifies the database to connect to. The second parameter determines the user permissions level. */
class mysqlConnection{
var $user_pass;
var $dbh;
var $db_identifier;
var $access_level;
function mysqlConnection($db_identifier,$access_level){
$this->user_pass = array(
LEVEL_READ_INSERT_DELETE =>array('UNAME'=>'xyz','PASS'=>'xyz'),
LEVEL_INSERT =>array('UNAME'=>'xyz3','PASS'=>'xyz'),
LEVEL_READ =>array('UNAME'=>'xyz4','PASS'=>'xyz '));
//CLOSE ANY OPEN CONNECTIONS
$this->dbclose();
$this->db_identifier = $db_identifier;
$this->access_level = $access_level;
$db_identifier = lookupTableName($db_identifier);//THIS FUNCTION WILL RETURN THE REQUIRED DATABASE NAME
$this->dbh=@mysql_connect ('localhost', $this->user_pass[$access_level]['UNAME'], $this->user_pass[$access_level]['PASS'])
or ('Unable to connect to the database ');
@mysql_select_db ($db_identifier)
or ('Unable to connect to database');
}
function dbclose(){
@mysql_close();
}
function getDBIdentifier(){ return $this->db_identifier;}
function getAccessLevel(){ return $this->access_level;}
}
?>Code: Select all
<?php
/* CONNECT TO DB*/
$MSC = new mysqlConnection(DB1,LEVEL_READ_INSERT_DELETE);
/* RUN QUERY */
$qry = "INSERT INTO TABLENAME(VAL1,VAL2) VALUES('$someVar',$somevar2) WHERE ID=$xyz";
$result = @mysql_query($qry);
if(!$result){
insertErrorIn_Error_Log($MSC,ERROR_ID_1,$qry);
}
$qry = "SELECT * FROM TABLE2 WHERE ID=$xyz";
...
..
.
function insertErrorIn_Error_Log($dbConn,$error_id,$qry){
$orig_dbIdent = $dbConn->getDBIdentifier();
$orig_accessLev = $dbConn->getAccessLevel();
$MSC = new mysqlConnection(DB2,LEVEL_INSERT);
$qry = "INSERT INTO ERROR_TABLE($error_id,'$qry')";
@mysql_query($qry);
//SET CONNECTION BACK TO ORIGINAL CONNECTION
$MSC = new mysqlConnection($orig_dbIdent,$orig_accessLev);
}
?>