Delete transaction

The delete transaction follows exactly the same steps as the insert and update transactions, even though there is no data to add.

The first thing that occurs when adding a new transaction into a page is the inclusion of the Transaction Engine 3 classes. They are included in a file called tNG.inc.php, in the includes/tng folder on the server. This folder is created automatically when using a Transaction Engine 3 feature in one of the site's pages:

// Load the Transaction Engine 3 classes
require_once('../includes/tng/tNG.inc.php');

 

As you can have multiple transactions on page, each one must register with the page's unique dispatcher, so that it can establish a coherent order of execution:

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

 

The standard connection is transformed into a Transaction Engine 3 connection and made available through a variable:

// Make unified connection variable
$conn_localhost = new tNG_connection($localhost, $database_localhost);

 

This code section creates the actual transaction: a delete one. As you can see, all is done object oriented, creating a new delete transaction being reduced to creating an instance of an object:

// Make an instance of the transaction object
$deleteTransaction = new tNG_delete($conn_localhost);
$tNGs->addTransaction($deleteTransaction);

 

This code section register triggers with the transaction. In this case we only have 2triggers: a starter, which verifies if data has been received through POST, and an end trigger that performs the page redirect after the transaction and all other triggers executed successfully:

// Register triggers
$deleteTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "id_com");
$deleteTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");

 

In order to delete only one record, the one that has been selected in another page, the primary column must be selected. Also, the table from which to delete is selected in this code section:

// Add columns
$deleteTransaction->setTable("company_com");
$deleteTransaction->setPrimaryKey("id_com", "NUMERIC_TYPE", "GET", "id_com");

 

All that remains is to actually call the transaction for execution:

// Execute all the registered transactions
$tNGs->executeTransactions();

 

As you can see from the three code examples, the only difference lies in the name of the object. The methods for the different objects are pretty much the same.