Elgg\Database::updateData PHP Method

updateData() public method

Update the database.
public updateData ( string $query, boolean $get_num_rows = false, array $params = [] ) : boolean | integer
$query string The query to run.
$get_num_rows boolean Return the number of rows affected (default: false).
$params array Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
return boolean | integer
    public function updateData($query, $get_num_rows = false, array $params = [])
    {
        if ($this->logger) {
            $this->logger->info("DB query {$query}");
        }
        $this->invalidateQueryCache();
        $stmt = $this->executeQuery($query, $this->getConnection('write'), $params);
        if ($get_num_rows) {
            return $stmt->rowCount();
        } else {
            return true;
        }
    }

Usage Example

Example #1
0
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = $this->get($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $sql = "UPDATE {$this->db->prefix}annotations\n\t\t\t(name, value, value_type, access_id, owner_guid)\n\t\t\tVALUES\n\t\t\t(:name, :value, :value_type, :access_id, :owner_guid)\n\t\t\tWHERE id = :annotation_id";
     $result = $this->db->updateData($sql, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':annotation_id' => $annotation_id]);
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = $this->get($annotation_id);
         $this->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
All Usage Examples Of Elgg\Database::updateData