setQueryOption()

Adds optional raw SQL modifiers to SELECT queries. Common use cases include FOR UPDATE (row locking) or SQL_CALC_FOUND_ROWS (deprecated in MySQL 8+). This method does not affect INSERT, UPDATE or DELETE statements.

Signature:

public function setQueryOption(string $option): self

Example: Lock row for update

// Lock row for exclusive access
$db->setQueryOption('FOR UPDATE');
$db->where('id', 42);
$user = $db->getOne('test_users');
Note: You can only set one query option per query. Subsequent calls to setQueryOption() will override the previous one.

Use Cases

  • Use FOR UPDATE to lock rows during a transaction
  • Use SQL_CALC_FOUND_ROWS for legacy pagination (discouraged)
  • Add MySQL-specific query modifiers to tune performance

See Also