Sample File: delete-by-id.php

The Code

<?php

//outline (see source for full code)
require_once("include/include.php");

//lookup the Customer row with a primay key (CustomerId) of 1
$Customer = $GLOBALS["db"]["Customer"]->LookupRow(1);

//note- as a shortcut to LookupRow($id) above, we could do any of the following:
//$Customer = $GLOBALS["db"]["Customer"](1);
//$Customer = $GLOBALS["db"]["Customer"]->LookupRow(array(
//	"CustomerId" => 1
//));
//$Customer = $GLOBALS["db"]["Customer"]["CustomerId"]->LookupRow(1);

// -- BEFORE DELETE --

//print a message if the customer does not exist
if(!$Customer->Exists()){
	echo "Customer with CustomerId=1 not found to delete.";
}

//delete the row from the database. It`s fine if the row doesn`t exist.
$numRowsDeleted = $Customer->Delete();

// -- AFTER DELETE --
?>
https://github.com/cirkuitnet/PHP-SmartDB/blob/master/samples/basic/delete-by-id.php

Debugging Output

Row Before Delete

CustomerId: 1
Name: Miss Piggy
EmailAddress: queen@muppets.com
Gender: Male
EmailVerified: 1
DateLastModified: 2024-10-02 11:15:45
DateCreated: 2024-10-02 11:15:45
IsDirty:
Exists: 1
HasErrors:

Delete() - Number Of Rows Affected

1

Row After Delete

CustomerId:
Name: Miss Piggy
EmailAddress: queen@muppets.com
Gender: Male
EmailVerified: 1
DateLastModified: 2024-10-02 11:15:45
DateCreated: 2024-10-02 11:15:45
IsDirty:
Exists:
HasErrors: