Each time I use $dbAP->delete(), MySQL 4.1.12 platform, tables, database, everything, wiped off the face of the earth!!
If someone could look at the code (sorry I will have to post its entirety for you to see how everything works) and tell me what is going on, I'd appreciate it.
I've used this class I wrote for years w/o a single problem in any other database platform (MySQL 3.23.58 - MySQL 4.1.17 without a hitch) and suddenly on this one database platform here on a development server running RHEL 4 and Apache 2.0.54, using PHP 4.3.8, each time I run the delete() method, MySQL has to be completely rebuilt from the ground up (happened 3 times today!)
Please help
<?php
/**
* File containing project-scope classes for database actions for all sections
*
* @author Phil Powell
* @version 1.1.0
* @package IMA
* @filesource
*/
/*------------------------------------------------------------------------------------------------------------------------------------
File: DB_ACTION.INC.PHP
Author: PHIL POWELL
Created: 2/17/2004
Modified: 7/13/2005
Purpose: Controller classes for all actions including file and database actions
Dependencies:
1) ../client_globals.inc.php for inclusion of all required client-scope vars and functions
2) ../project_globals.inc.php for inclusion of all required project-scope vars and functions
3) ../include/classes.inc.php for inclusion of all required project-scope classes
Cookies: $_COOKIE["$projectFolderName"] or $willAuthenticate set to false for this to run
Sessions: Session variables and collections may be present but only specifically necessary in various class scopes
Privacy Scope: Only viewable through requesting URL
------------------------------------------------------------------------------------------------------------------------------------*/
/**
* Class for handling all database actions including associations and disassociations, table locking and optimization
*
* @author Phil Powell
* @version 1.1.0
* @package IMA
*/
class DBActionPerformer extends MethodGeneratorForActionPerformer {
/**
* @access protected
* @var int $id
*/
var $id;
/**
* @access protected
* @var DBConnection $dbConnObj
*/
var $dbConnObj;
/**
* @access public
* @var resource $dbConn
*/
var $dbConn;
function DBActionPerformer($id = '') { // CONSTRUCTOR
global $dbHost, $dbPort, $dbUser, $dbPwd, $dbDefaultName;
$this->id = $id;
$this->dbConnObj =& new DBConnection($dbHost, $dbPort, $dbUser, $dbPwd, $dbDefaultName);
}
//---------------------------------------------* DB ACTION METHODS *----------------------------------------------
/**
* Connect to database
*
* @access public
*/
function &connect() { // STATIC VOID METHOD
$this->dbConn = $this->dbConnObj->connect();
if (!$this->dbConn) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => 'Could not connect to the database'));
}
}
/**
* Delete from database table named after $section
*
* @access public
* @param mixed $extraCriteriaSQL (optional)
* @param boolean $willNotRedirect (default false)
* @see MySQLQuery
*/
function delete($extraCriteriaSQL = '', $willNotRedirect = false) { // VOID METHOD
global $section, $action, $sectionArray, $redirectArray, $displayableSectionArray, $assocDBTableNameArray;
@reset($sectionArray);
if (!$this->getDBConn()) @$this->connect(); // RECONNECT
if ($this->isSuccessful) {
$this->lock(); // LOCK TABLE
$sql = $this->getGeneratedSQLBySection('delete', '', '', $extraCriteriaSQL);
/*------------------------------------------------------------------------------------------------------------
Because of the sensitive nature of deletions, it is best to handle them within the scope of a
successful db connection instead of others that assume connection based upon an object-scope boolean
$this->isSuccessful
-------------------------------------------------------------------------------------------------------------*/
$query = new MySQLQuery($sql, $this->getDBConn());
@$query->runQuery(); // WILL ALWAYS HAVE TO BE TRUE
}
$this->unlock(); // UNLOCK TABLES
if ($willNotRedirect) @$this->disconnect();
if ($this->isSuccessful) $this->optimize(); // OPTIMIZE AFTER COMPLETION
if ($this->isSuccessful && @in_array($section, $displayableSectionArray))$albumQS = '&chooseAlbum=1&album=' . urlencode($_POST['album']);
if ($this->isSuccessful && !$willNotRedirect && $redirectArray[$section]['delete'] && !$_POST['willAssociate'])
echo $this->getHTMLRedirect('delete', "&willFlushResult=1$albumQS");
}
/**
* Disconnect from database
*
* @access public
*/
function &disconnect() { // STATIC VOID METHOD
if ($this->dbConn) $this->dbConnObj->close();
$this->dbConn = null;
}
/**
* Lock tables
*
* @access private
* @param mixed $section (optional) - will pull from globalized $section if not passed as parameter
* @see MySQLQuery
*/
function &lock($section = '') { // STATIC VOID METHOD
if (!$section) global $section;
// NEW 6/2/2004: BENEFIT EFFICIENCY BY LOCKING TABLES BEFORE YOU INSERT
$query =& new MySQLQuery("LOCK TABLES $section WRITE", $this->getDBConn());
if (@!$query->runQuery() || mysql_error()) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => "Could not lock table \"$section\":" . nl2br(mysql_error())));
}
$query = null;
}
/**
* Optimize table named after $section
*
* @access private
* @see MySQLQuery
*/
function &optimize() { // STATIC VOID METHOD
// THIS IS TO OPTIMIZE THE DB FOR BETTER HANDLING OF DB-RELATED DATA
global $section;
if (!$this->dbConn) @$this->connect();
if ($this->isSuccessful) {
// NO FURTHER NEED TO CHECK FOR ERRORS FROM HERE SINCE OPTIMIZATION IS AN OUTSIDE SEAMLESS PROCESS NON-CRITICAL TO SITE
$query =& new MySQLQuery("OPTIMIZE TABLE $section", $this->dbConn);
$query->runQuery();
$query = null;
// NEW 2/1/2005 - DO NOT DISCONNECT AFTER THIS AS OTHER DB-RELATED ACTIONS (AND CALL TO DISCONNECT) MAY FOLLOW
}
}
/**
* Select by using inherited method getGeneratedSQLBySection to retrieve results
*
* @access public
* @param mixed $orderBy (optional)
* @param mixed $asc (optional)
* @param mixed $extraCriteriaSQL (optional)
* @return object $result array of objects pointing to each row returned
* @see MySQLQuery
*/
function &select($orderBy = '', $asc = '', $extraCriteriaSQL = '') { // STATIC ARRAY-OF-OBJECTS QUERY METHOD
global $section, $action, $redirectArray, $editActionNameArray;
$willKeepConnectionAlive = ($this->id && strcmp(strtolower($action), $editActionNameArray[$section]) == 0);
if (!$this->getDBConn()) @$this->connect();
if ($this->isSuccessful) { // SUCCESSFUL DB CONNECTION
$sql = $this->getGeneratedSQLBySection('select', $orderBy, $asc, $extraCriteriaSQL);
$query =& new MySQLQuery($sql, $this->dbConn);
$result =@ $query->getResult();
if (mysql_error()) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => "Could not select ${section}s: " . nl2br(mysql_error())));
}
$query = null;
}
if (!$willKeepConnectionAlive) @$this->disconnect();
if ($this->isSuccessful && $redirectArray[$section]['select']) echo $this->getHTMLRedirect('select');
return $result;
}
/**
* Unlock all tables
*
* *NOTE* For coding consistency this method must exist, however, because at end of application run all MySQL tables are automatically freed, there is no
* need to free them via 'UNLOCK TABLES' SQL command. In fact, upon doing so will cause a false result inasmuch as the tables will not actually be unlocked
* (possible cause: threading)
*
* @abstract
* @access private
* @todo Obtain information to allow for actual table unlocking when exiting application level scope
*/
function &unlock() {} // STATIC VOID METHOD
//---------------------------------------------* END OF DB ACTION METHODS *----------------------------------------------
}
?>
It's of course time sensitive (even though the deadline for application launch was this morning and I missed it by a good 3 hours while destroying the database platform in the process 3 times)
Phil