Solar_Sql_Adapter_Pgsql::delete()

public int Solar_Sql_Adapter_Pgsql::delete ( string $table , string|array $where )

Deletes rows from the table based on a WHERE clause.

Inherited from Solar_Sql_Adapter.

Parameters

  • (string) $table: The table to delete from.

  • (string|array) $where: The SQL WHERE clause to limit which rows are deleted.

Returns

  • (int) The number of rows affected.

Description

Deletes rows from the table based on a WHERE clause.

For example ...

<?php
$sql = Solar::factory('Solar_Sql');

$table = 'events';
$where = $sql->quoteInto('status = ?', 'cancelled');
$rows_affected = $sql->delete($table, $where);

// calls 'DELETE FROM events WHERE status = "cancelled"'

For the $where parameter, you can also pass multiple WHERE conditions as an array to be "AND"ed together.

<?php
$sql = Solar::factory('Solar_Sql');

$table = 'events';
$where = array(
    "date >= ?"  => '2006-01-01',
    "date <= ?"  => '2006-01-31',
    "status = ?" => 'cancelled',
);

$rows_affected = $sql->delete($table, $where);

// calls:
// DELETE FROM events WHERE date >= "2006-01-01"
// AND date <= "2006-01-31" AND status = "cancelled"


Local