MySQL::DeleteRows PHP Method

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
    public function DeleteRows($tableName, $whereArray = null)
    {
        $this->ResetError();
        if (!$this->IsConnected()) {
            $this->SetError("No connection");
            return false;
        } else {
            $sql = self::BuildSQLDelete($tableName, $whereArray);
            // Execute the UPDATE
            if (!$this->Query($sql)) {
                return false;
            } else {
                return true;
            }
        }
    }

Usage Example

示例#1
0
文件: Mysql.php 项目: kimai/kimai
 /**
  * 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;
 }
All Usage Examples Of MySQL::DeleteRows