Manage() provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// This function performs simple record functions of add, delete and gets
//
function Manage($ses) {
echo "<h4>MANAGE</h4>\n";
// delete any existing records
Delete_Records($ses);
// populate the table with data
Add_CustomerMaster_Records($ses);
// display contents of table
Display_Records($ses);
// update a record under locking control
Update_CustomerMaster_Records($ses);
// display again after update and effects of lock
Display_Records($ses);
}
//
// Delete_Records()
//
// This function deletes all the records in the table
//
function Delete_Records ($ses) {
echo "Delete records...<br>\n";
$qry = $ses->exec("DELETE FROM custmast");
if (!$qry)
if (0000 == $ses->errorCode())
return;
else
Handle_Error($ses, "exec(DELETE)");
}
//
// Add_CustomerMaster_Records()
//
// This function adds records to table CustomerMaster from an
// array of strings
//
function Add_CustomerMaster_Records ($ses) {
echo "Add records...<br>\n";
$data = array(
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
);
if (!$ses->beginTransaction())
Handle_Error($ses, "beginTransaction()");
foreach ($data as $values) {
$qry = $ses->exec("INSERT INTO custmast VALUES $values");
if (!$qry)
Handle_Error($ses, "exec(INSERT)");
}
if (!$ses->commit())
Handle_Error($ses, "commit");
}
//
// Display_Records()
//
// This function displays the contents of a table.
//
function Display_Records ($ses) {
echo "Display records...<br>\n";
$qry = $ses->query("SELECT cm_custnumb \"Number\", cm_custname \"Name\" FROM custmast");
if (!$qry)
Handle_Error("query(SELECT)");
else {
print("<TABLE border=1><TR><TH>Number</TH><TH>Name</TH></TR>\n");
foreach ($qry as $row)
print "\t\t\t<TR><TD>" . $row['Number'] . "</TD><TD>" . $row['Name'] . "</TR>\n";
print("\t\t</TABLE>\n");
if ($qry->errorCode())
Handle_Error($qry, "fetch()");
$qry = null;
}
}
//
// Update_CustomerMaster_Records()
//
// Update one record under locking control to demonstrate the effects
// of locking
//