DeleteRows() public method

Deletes rows in a table based on a WHERE filter (can be just one or many rows based on the filter)
public DeleteRows ( string $tableName, array $whereArray = null ) : boolean
$tableName string The name of the table
$whereArray array (Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect). If not specified then all values in the table are deleted.
return boolean Returns TRUE on success or FALSE on error
Ejemplo n.º 1
0
 /**
  * Set the groups in which the user is a member in.
  * @param int $userId   id of the user
  * @param array $groups  map from group ID to membership role ID
  * @return false|null       true on success, false on failure
  * @author sl
  */
 public function setGroupMemberships($userId, array $groups = null)
 {
     $table = $this->getGroupsUsersTable();
     if (!$this->conn->TransactionBegin()) {
         $this->logLastError('setGroupMemberships');
         return false;
     }
     $data['userID'] = MySQL::SQLValue($userId, MySQL::SQLVALUE_NUMBER);
     $result = $this->conn->DeleteRows($table, $data);
     if (!$result) {
         $this->logLastError('setGroupMemberships');
         if (!$this->conn->TransactionRollback()) {
             $this->logLastError('setGroupMemberships_rollback');
         }
         return false;
     }
     foreach ($groups as $group => $role) {
         $data['groupID'] = MySQL::SQLValue($group, MySQL::SQLVALUE_NUMBER);
         $data['membershipRoleID'] = MySQL::SQLValue($role, MySQL::SQLVALUE_NUMBER);
         $result = $this->conn->InsertRow($table, $data);
         if ($result === false) {
             $this->logLastError('setGroupMemberships');
             if (!$this->conn->TransactionRollback()) {
                 $this->logLastError('setGroupMemberships_rollback');
             }
             return false;
         }
     }
     if (!$this->conn->TransactionEnd()) {
         $this->logLastError('setGroupMemberships');
         return false;
     }
     return true;
 }
function content_delete_permanently($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('content_delete_permanently');
    if (is_numeric($id)) {
        /* xóa bảng content */
        $tableName = DB_PREFIX . "content";
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /** Tìm các sub content */
        $whereArray = array('parent' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        $ids = array();
        while ($row = $hmdb->Row()) {
            $ids[] = $row->id;
        }
        foreach ($ids as $delete_id) {
            /** xóa các sub content */
            $tableName = DB_PREFIX . "content";
            $whereArray = array('id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
            /** xóa các sub content field */
            $tableName = DB_PREFIX . "field";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id), 'object_type' => MySQL::SQLValue('content'));
            $hmdb->DeleteRows($tableName, $whereArray);
            /* xóa các relationship */
            $tableName = DB_PREFIX . "relationship";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
            /** xóa các sub request */
            $tableName = DB_PREFIX . "request_uri";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
        }
        /* xóa bảng field */
        $tableName = DB_PREFIX . "field";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('content'));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng relationship */
        $tableName = DB_PREFIX . "relationship";
        $whereArray = array('object_id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng request uri */
        $tableName = DB_PREFIX . "request_uri";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('content'));
        $hmdb->DeleteRows($tableName, $whereArray);
    }
}
function taxonomy_delete_permanently($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('taxonomy_delete_permanently');
    if (isset_taxonomy_id($id) == TRUE) {
        $tableName = DB_PREFIX . "taxonomy";
        /* update lại parent các sub taxonomy */
        $valuesArray = array('parent' => MySQL::SQLValue(0));
        $whereArray = array('parent' => MySQL::SQLValue($id));
        $hmdb->UpdateRows($tableName, $valuesArray, $whereArray);
        /* xóa bảng taxonomy */
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng field */
        $tableName = DB_PREFIX . "field";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('taxonomy'));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng relationship */
        $tableName = DB_PREFIX . "relationship";
        $whereArray = array('object_id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng request uri */
        $tableName = DB_PREFIX . "request_uri";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('taxonomy'));
        $hmdb->DeleteRows($tableName, $whereArray);
    }
}
Ejemplo n.º 4
0
    // Show the error and kill the script
    $db->Kill();
} else {
    // No error, show the new record's ID
    echo "The new record's ID is: " . $db->GetLastInsertID() . "\n<br />\n";
    // Show the record using the values array to generate the WHERE clause
    // We will use the SelectRows() method to query the database
    $db->SelectRows("Test", $values);
    // Show the results in an HTML table
    echo $db->GetHTML();
}
// =========================================================================
// Example to delete a row (or rows) in a table matching a filter
// =========================================================================
// Now let's delete that record using the same array for the WHERE clause
$db->DeleteRows("Test", $values);
// =========================================================================
// Example to update an existing row into a table
// =========================================================================
// Create an array that holds the update information
// $arrayVariable["column name"] = formatted SQL value
$update["Color"] = MySQL::SQLValue("Red");
$update["Age"] = MySQL::SQLValue(123, MySQL::SQLVALUE_NUMBER);
// Create a filter array the detemrines which record(s) to process
// (you can specify more than one column if needed)
$where["TestID"] = MySQL::SQLValue(1, "integer");
// Execute the update
$result = $db->UpdateRows("test", $update, $where);
// If we have an error
if (!$result) {
    // Show the error and kill the script
Ejemplo n.º 5
0
/** Ajax xóa thư mục */
function del_media_group($args)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    $id = $args['group_id'];
    if (is_numeric($id)) {
        /** Xóa thư mục */
        $path = BASEPATH . '/' . HM_CONTENT_DIR . '/uploads/' . get_media_group_part($id);
        DeleteDir($path);
        $tableName = DB_PREFIX . "media_groups";
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /** Xóa các file trong thư mục */
        $tableName = DB_PREFIX . "media";
        $whereArray = array('media_group_id' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            while ($row = $hmdb->Row()) {
                $id_media_file = $row->id;
                delete_media($id_media_file);
            }
        }
        /** Xóa thư mục con */
        $tableName = DB_PREFIX . "media_groups";
        $whereArray = array('parent' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            while ($row = $hmdb->Row()) {
                $id_sub_folder = $row->id;
                del_media_group(array('group_id' => $id_sub_folder));
            }
        }
    }
}