예제 #1
0
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");
    }
}
예제 #2
0
function _DELETE($Table, $VARS = null)
{
    global $TABLES, $DBOBJ, $Connection, $PARAMS;
    if ($VARS == null) {
        $VARS = $PARAMS;
    }
    $MongoDB = $DBOBJ->GetMongoDB();
    $Collection = $MongoDB->{$Table};
    $UniqueVars = _getUniqueTableVars($Table);
    $attrs = array();
    $NeedAnd = false;
    foreach ($VARS as $var => $val) {
        if ($var == $TABLES[$Table]['META']['KEY']) {
            $attrs[$TABLES[$Table]['META']['KEY']] = new MongoID($VARS[$TABLES[$Table]['META']['KEY']]);
            $NeedAnd = true;
        } elseif (in_array($var, $UniqueVars) && strlen($val) > 0) {
            $attrs[$var] = $val;
            $NeedAnd = true;
        }
    }
    if ($NeedAnd == false) {
        $msg = "You have supplied none of the required parameters to make this delete.  At least one of the following is required: ";
        foreach ($UniqueVars as $var) {
            $msg .= $var . " ";
        }
        return array(false, $msg);
    }
    $Status = $DBOBJ->GetStatus();
    if ($Status === true) {
        $count = $Collection->count($attrs);
        if ($count > 1) {
            return array(false, "More than one item matches these parameters.  Only one row can be deleted at a time.");
        } elseif ($count < 1) {
            return array(false, "The item you are requesting to delete is not found");
        }
        $resp = $Collection->remove($attrs);
        if ($resp === true) {
            return array(true, true);
        } else {
            return array(false, $resp);
        }
    } else {
        return array(false, $Status);
    }
}