Product Documentation

FairCom SQL for PHP

Previous Topic

Next Topic

Manage

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_Record($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 = ctsql_query("DELETE FROM custmast", $ses);

if (!$qry)

if (100 == ctsql_errno())

return;

else

Handle_Error("ctsql_query(DELETE)");

if (!ctsql_commit($ses))

Handle_Error("ctsql_commit()");

}

//

// 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')"

);

foreach ($data as $values) {

$qry = ctsql_query("INSERT INTO custmast VALUES $values", $ses);

if (!$qry)

Handle_Error("ctsql_query(INSERT)");

}

if (!ctsql_commit($ses))

Handle_Error("ctsql_commit()");

}

//

// Display_Records()

//

// This function displays the contents of a table.

//

function Display_Records ($ses) {

echo "Display records...<br>\n";

$qry = ctsql_query("SELECT cm_custnumb \"Number\", cm_custname \"Name\" FROM custmast", $ses);

if (!is_resource($qry))

Handle_Error("ctsql_query(SELECT)");

else {

print("<TABLE border=1><TR><TH>Number</TH><TH>Name</TH></TR>\n");

while ($values = ctsql_fetch_row($qry)) {

print("<TR>");

foreach ($values as $content) {

if (is_null($content))

print ("<TD>NULL</TD>");

else

print ("<TD>$content</TD>");

}

print("</TR>\n");

}

print("</TABLE>\n");

if (ctsql_errno())

Handle_Error("ctsql_fetch_row()");

ctsql_free_result($qry);

}

}

//

// Update_CustomerMaster_Records()

//

// Update one record under locking control to demonstrate the effects

// of locking

//

TOCIndex