DQL (Doctrine Query Language) - DELETE queries.php 968 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1
<code>
2 3
DELETE FROM <component_name>
    [WHERE <where_condition>]
hansbrix's avatar
hansbrix committed
4
    [ORDER BY ...]
5
    [LIMIT <record_count>]
hansbrix's avatar
hansbrix committed
6 7 8 9 10 11 12 13 14
</code>

* The DELETE statement deletes records from //component_name// and returns the number of records deleted.

* The optional WHERE clause specifies the conditions that identify which records to delete.
Without WHERE clause, all records are deleted.

* If the ORDER BY clause is specified, the records are deleted in the order that is specified.

15
* The LIMIT clause places a limit on the number of rows that can be deleted.
hansbrix's avatar
hansbrix committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
The statement will stop as soon as it has deleted //record_count// records.



<code type="php">
$q    = 'DELETE FROM Account WHERE id > ?';

$rows = $this->conn->query($q, array(3));

// the same query using the query interface

$q = new Doctrine_Query();

$rows = $q->delete('Account')
          ->from('Account a')
          ->where('a.id > ?', 3)
          ->execute();
33

hansbrix's avatar
hansbrix committed
34 35
print $rows; // the number of affected rows
</code>