function Query::comment

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query::comment()
  2. 8.9.x core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query::comment()
  3. 10 core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query::comment()
  4. 11.x core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query::comment()

Adds a comment to the query.

By adding a comment to a query, you can more easily find it in your query log or the list of active queries on an SQL server. This allows for easier debugging and allows you to more easily find where a query with a performance problem is being generated.

The comment string will be sanitized to remove * / and other characters that may terminate the string early so as to avoid SQL injection attacks.


$comment: The comment string to be inserted into the query.

Return value

Query The called object.


includes/database/, line 413


Base class for query builders.


public function comment($comment) {
    $this->comments[] = $comment;
    return $this;

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