Deleting a Single Row with delete()

This example shows how to retrieve and delete an existing row in the Book table using the delete() method. In this example, we will retrieve and delete a row with a BookID of 23



require_once('config.php');

//Retrieve the row from the database and populate a Book object
$myBook = Book::retrieveByPK(23);

//Delete the row
$myBook->delete();

?>

Deleting Multiple Rows at Once with doDelete()

doDelete() is used the same as doSelect(), but it deletes the rows instead of selecting them. It also returns the number of rows that were deleted.



require_once('config.php');

//Create new instance of Query
$q = new Query;

//Add search criteria
$q->add('Author',$_POST['Author']); $q->setLimit(314);

//Delete all the books from the database that match the query criteria
$deleteCount = Book::doDelete($q);

//Print the number of books that were deleted
echo "$deleteCount books were deleted.";

?> 

(503) 746-9116 | 17933 NW Evergreen Parkway, Suite 220 | Beaverton, Oregon 97006