function _DELETE($Table, $VARS = null) { global $TABLES, $DBOBJ, $Connection, $PARAMS; if ($VARS == null) { $VARS = $PARAMS; } if (_tableCheck($Table)) { $UniqueVars = _getUniqueTableVars($Table); $AllTableVars = _getAllTableCols($Table); $SQL = "DELETE FROM `" . $Table . "` WHERE ( "; $SQL2 = "SELECT COUNT(1) FROM `" . $Table . "` WHERE ( "; $NeedAnd = false; if (is_array($VARS)) { foreach ($VARS as $var => $val) { if (in_array($var, $AllTableVars) && strlen($val) > 0) { if ($NeedAnd) { $SQL .= " AND "; $SQL2 .= " AND "; } $SQL .= ' `' . $var . '` = "' . $val . '" '; $SQL2 .= ' `' . $var . '` = "' . $val . '" '; $NeedAnd = true; } } } if ($NeedAnd == false) { $msg = "You have supplied none of the required parameters to make this query. At least one of the following is required: "; foreach ($UniqueVars as $var) { $msg .= $var . " "; } return array(false, $msg); } $SQL .= " ) ;"; // There is no limit to allow more than one removal $SQL2 .= " ) ;"; // $Status = $DBOBJ->GetStatus(); if ($Status === true) { $DBOBJ->Query($SQL2); $Status = $DBOBJ->GetStatus(); if ($Status === true) { $results = $DBOBJ->GetResults(); if ($results[0]['COUNT(1)'] > 1) { return array(false, "More than one item matches these parameters. Only one row can be deleted at a time."); } elseif ($results[0]['COUNT(1)'] < 1) { return array(false, "The row specified for deletion cannot be found."); } } else { return array(false, "The item you are requesting to delete is not found"); } $DBOBJ->Query($SQL); $Status = $DBOBJ->GetStatus(); if ($Status === true) { return array(true, true); } else { return array(false, $Status); } } else { return array(false, $Status); } } else { return array(false, "This table cannot be found"); } }
function only_table_columns($DATA, $Table) { $CleanData = array(); foreach ($DATA as $param => $val) { if (in_array($param, _getAllTableCols($Table))) { $CleanData[$param] = $val; } } return $CleanData; }