Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function UpdateQuery::__toString

Implements PHP magic __toString method to convert the query to a string.

Return value

string The prepared statement.

Overrides Query::__toString

1 call to UpdateQuery::__toString()
UpdateQuery_mysql::__toString in includes/database/mysql/query.inc
Implements PHP magic __toString method to convert the query to a string.
1 method overrides UpdateQuery::__toString()
UpdateQuery_mysql::__toString in includes/database/mysql/query.inc
Implements PHP magic __toString method to convert the query to a string.

File

includes/database/query.inc, line 1192

Class

UpdateQuery
General class for an abstracted UPDATE operation.

Code

public function __toString() {
 if (!is_array ($this->expressionFields ) || !is_array ($this->fields )) {
 if (version_compare (PHP_VERSION, '7.4', '>=')) {
 throw new UnexpectedValueException();
 }
 else {
 drupal_trigger_fatal_error ('Unexpected Value');
 }
 }
 // Create a sanitized comment string to prepend to the query.
 $comments = $this->connection 
 ->makeComment ($this->comments );
 // Expressions take priority over literal fields, so we process those first
 // and remove any literal fields that conflict.
 $fields = $this->fields ;
 $update_fields = array();
 foreach ($this->expressionFields  as $field => $data) {
 $update_fields[] = $field . '=' . $data['expression'];
 unset($fields[$field]);
 }
 $max_placeholder = 0;
 foreach ($fields as $field => $value) {
 $update_fields[] = $field . '=:db_update_placeholder_' . $max_placeholder++;
 }
 $query = $comments . 'UPDATE {' . $this->connection 
 ->escapeTable ($this->table ) . '} SET ' . implode (', ', $update_fields);
 if (count ($this->condition )) {
 try {
 $this->condition 
 ->compile ($this->connection , $this);
 } catch (InvalidQueryConditionOperatorException $e) {
 drupal_trigger_fatal_error ($e->getMessage());
 }
 // There is an implicit string cast on $this->condition.
 $query .= "\nWHERE " . $this->condition ;
 }
 return $query;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.