Product Documentation

FairCom SQL for PHP PDO

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) {

print("\t<h4>MANAGE</h4>\n");

// delete any existing records

Delete_Records($ses);

// populate the table with data

Add_Records($ses);

// display contents of table

Display_Records($ses);

}


Several functions are defined in this section of the code:

//

// Delete_Records()

//

// This function deletes all the records in the table

//

function Delete_Records ($ses) {

print("\t\tDelete records...<br>\n");

$qry = $ses->exec("DELETE FROM custmast");

if (!$qry)

if (0000 == $ses->errorCode())

return;

else

Handle_Error($ses, "exec(DELETE)");

}

//

// Add_Records()

//

// This function adds records to a table in the database from an

// array of strings

//

function Add_Records ($ses) {

print("\t\tAdd 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) {

print("\t\tDisplay records...<br>\n");

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

$qry = $ses->query('SELECT cm_custnumb "Number", cm_custname "Name" FROM custmast');

if (!$qry)

Handle_Error($ses, "query(SELECT)");

foreach ($qry as $row) {

print("\t\t\t<TR>");

print "<TD>" . $row['Number'] . "</TD><TD>" . $row['Name'] . "</TD>";

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

}

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

if ($qry->errorCode())

Handle_Error($qry, "fetch()");

$qry = null;

}

TOCIndex