Sample File: lookup-update-by-email.php

The Code

<?php

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

//lookup the Customer row with the EmailAddress = "jfrost@winter.com"
$Customer = $GLOBALS["db"]["Customer"]->LookupRow(array(
	"EmailAddress" => "jfrost@winter.com"
));

//note- instead of LookupRow() on the table, we can LookupRow() from the column:
//$Customer
//	= $GLOBALS["db"]["Customer"]["EmailAddress"]->LookupRow("jfrost@winter.com");

//lets print a message if the customer does not exist
if(!$Customer->Exists()){
	echo "Customer with EmailAddress=jfrost@winter.com 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-email.php

Debugging Output

Errors Found

Customer with EmailAddress=jfrost@winter.com not found to update!

Row Before Update And Commit

CustomerId:
Name:
EmailAddress: jfrost@winter.com
Gender:
EmailVerified: 0
DateLastModified:
DateCreated:
IsDirty: 1
Exists:
HasErrors: 'Name' field is required.
'Gender' field is required.

Row After Update, Before Commit

CustomerId:
Name:
EmailAddress: jfrost@winter.com
Gender: Male
EmailVerified: 0
DateLastModified:
DateCreated:
IsDirty: 1
Exists:
HasErrors: 'Name' field is required.

Errors Found

'Name' field is required.

Commit() - Number Of Rows Affected

0

Row After Update and Commit

CustomerId:
Name:
EmailAddress: jfrost@winter.com
Gender: Male
EmailVerified: 0
DateLastModified:
DateCreated:
IsDirty: 1
Exists:
HasErrors: 'Name' field is required.