Sample File: lookup-update-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);

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

// -- BEFORE UPDATE AND COMMIT --

//update the customer`s gender (we will just toggle it every time)
if($Customer["Gender"]() == "Male"){
	$Customer["Gender"] = "Female";
}
else{
	$Customer["Gender"] = "Male";
}

// -- AFTER UPDATE, BEFORE COMMIT --
 
//check for errors before we commit
//HasErrors() returns nothing when there are no errors
if( ($errors=$Customer->HasErrors()) ){
	echo "Errors found: ".$errors;	
}
else{
	//commit this row to the database
	$numRowsUpdated = $Customer->Commit();
}

// -- AFTER UPDATE AND COMMIT --
?>
https://github.com/cirkuitnet/PHP-SmartDB/blob/master/samples/basic/lookup-update-by-id.php

Debugging Output

Row Before Update and Commit

CustomerId: 1
Name: Miss Piggy
EmailAddress: queen@muppets.com
Gender: Female
EmailVerified: 1
DateLastModified: 2024-05-17 01:08:13
DateCreated: 2024-05-17 01:08:13
IsDirty:
Exists: 1
HasErrors:

Row After Update, Before Commit

CustomerId: 1
Name: Miss Piggy
EmailAddress: queen@muppets.com
Gender: Male
EmailVerified: 1
DateLastModified: 2024-05-17 01:08:13
DateCreated: 2024-05-17 01:08:13
IsDirty: 1
Exists: 1
HasErrors:

Commit() - Number Of Rows Affected

1

Row After Update and Commit

CustomerId: 1
Name: Miss Piggy
EmailAddress: queen@muppets.com
Gender: Male
EmailVerified: 1
DateLastModified: 2024-05-17 01:08:13
DateCreated: 2024-05-17 01:08:13
IsDirty:
Exists: 1
HasErrors: