->delete() – Delete items from table


int $DB_DataObject->delete ( boolean $useWhere )


Deletes data from the database, either using primary key or based on a whereAdd() method call. By default the delete will base its query on the set variables, however if you wish to use the whereAdd() method you should set the $useWhere parameter to DB_DATAOBJECT_WHEREADD_ONLY.


  • boolean $use_where - use the whereAdd() conditions (by default, delete will only use primary keys)

Return value

int number of rows affected or FALSE on failure


Possible PEAR_Error values
Error code Error message Meaning Solution
DB_* "*" see PEAR::DB see PEAR::DB
DB_DATAOBJECT_ERROR_NODATA "delete: No Data specifed for query $condition"    


This function can not be called statically.


Simple Delete

= new DataObjects_Person;

$person       = new DataObjects_Person;
$person->name 'test';
$person->age  21;

$person = new DataObjects_Person;
$person->whereAdd('age < 21');

Resulting SQL

FROM person WHERE person.id 12
person.id 12 )

DELETE FROM person WHERE person.name 'test' ) AND ( person.age 21 )

DELETE FROM person WHERE age 21 )
Update objects variables into database (Previous) Advanced Filters - ::
query(), ::
SelectAdd(), ::
whereAdd(), ::
Limit(), ::
OrderBy(), ::
GroupBy(), (Next)
Last updated: Thu, 17 Apr 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: tmilos1@gmail.com
Caution is needed, if we have a multicolumn primary key.
eg. primary key for person is (name, age)

$person = new DataObjects_Person;
$person->name = 'test';
$person->age = $some_age;

If $some_age is not set, then the $person->delete() method will delete all person's with the name 'test'.
In the case where the primary key is one column, we are protected from this kind of errors with raised error 'delete: No condition specifed for query'.