2.4.6. DELETE

2.4.6.1. Building The Query

2.4.6.1.1. FROM

Use the from() method to specify FROM expression.

$delete->from('foo');

2.4.6.1.2. WHERE

(All WHERE methods support implicit and sprintf() inline value binding.)

The Delete WHERE methods work just like their equivalent Select methods:

  • where() and andWhere() AND a WHERE condition
  • orWhere() ORs a WHERE condition
  • catWhere() concatenates onto the end of the most-recent WHERE condition
  • whereSprintf() and andWhereSprintf() AND a WHERE condition with sprintf()
  • orWhereSprintf() ORs a WHERE condition with sprintf()
  • catWhereSprintf() concatenates onto the end of the most-recent WHERE condition with sprintf()

2.4.6.1.3. ORDER BY

Some databases (notably MySQL) recognize an ORDER BY clause. You can add one to the Delete with the orderBy() method; pass each expression as a variadic argument.

// DELETE ... ORDER BY foo, bar, baz
$delete
    ->orderBy('foo')
    ->orderBy('bar', 'baz');

2.4.6.1.4. LIMIT and OFFSET

Some databases (notably MySQL and SQLite) recognize a LIMIT clause; others (notably SQLite) recognize an additional OFFSET. You can add these to the Delete with the limit() and offset() methods:

// LIMIT 10 OFFSET 40
$delete
    ->limit(10)
    ->offset(40);

2.4.6.1.5. RETURNING

Some databases (notably PostgreSQL) recognize a RETURNING clause. You can add one to the Delete using the returning() method, specifying columns as variadic arguments.

// DELETE ... RETURNING foo, bar, baz
$delete
    ->returning('foo')
    ->returning('bar', 'baz');

2.4.6.1.6. Flags

You can set flags recognized by your database server using the setFlag() method. For example, you can set a MySQL LOW_PRIORITY flag like so:

// DELETE LOW_PRIORITY foo WHERE baz = :__1__
$delete
    ->from('foo')
    ->where('baz = ', $baz_value)
    ->setFlag('LOW_PRIORITY');

2.4.6.2. Performing The Query

Once you have built the query, call the perform() method to execute it and get back a PDOStatement.

$result = $delete->perform(); // : PDOStatement