The delete transaction A transaction is a group of SQL statements whose effects are logically connected. Anything from simple queries to inserting, and deleting operations can be considered a transaction, as well as more complex groups of several statements which accomplish a specific task. 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 A dispatcher is a component of the Transaction Engine which contains all the transactions on a page and handles all interactions between that page and the transactions: executes the transactions, feeds the recordsets generated by the transactions to the page, displays the transaction's error messages, etc. 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 An END trigger is always the last action to be performed after executing a transaction. Use an END trigger to redirect the user to another page after performing an insert or an update transaction, for instance. that performs the page redirect The redirect server behavior A server behavior is a reusable component for server-side development. They add blocks of code to your pages for accomplishing specific tasks. Dreamweaver comes with several default server behaviors and the InterAKT extensions add many more to this list. loads a new site page after a transaction is executed. For instance, users could be automatically redirected to their inbox after they log in to the website. 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.
Related Topics