The main generated code sections are:
Defining the 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. connection. This object is used to create a database A database refers to data organized and stored on a computer that can be searched and retrieved by a computer program. Most industrial-strength and many smaller database applications can be addressed using SQL (Structured Query A query is a SQL command that will extract information from the tables of a database. Essentially, a query is a request for information from your database. Language). independence layer for Transaction Engine 3 Lite:
$conn_test = new tNG_connection($test, $database_test);
Defining the 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.:
$tNGs = new tNG_dispatcher("");
Create a transaction instance
$insertTNG1 = new tNG_insert($conn_test);
Add the created transaction to the dispatcher:
$tNGs->addTransaction($insertTNG1);
Register triggers (STARTER and END - Redirect The redirect server behavior 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.):
$insertTNG1->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "MM_Insert");
$insertTNG1->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");
Set the appropriate table to the transaction:
$insertTNG1->setTable("departments_dep");
Add all selected columns with all specified parameters (name, type, method, reference, default value):
$insertTNG1->addColumn("id_dep", "NUMERIC_TYPE", "POST", "id", "1");
$insertTNG1->addColumn("name_dep", "STRING_TYPE", "POST", "name");
For each column specified in the Columns grid in the Server Behavior interface, one addColumn() function call will exist.
addColumn(DB_FIELD_NAME, DB_TYPE, METHOD, REFERENCE, DEFAULT_VALUE);
Set the primary key:
If the transaction is of Insert, Update or Delete type, the primary key A primary key is one or more table columns whose values uniquely identify each record in a table. In general, a primary key is defined on a single column, but it is not uncommon to have it defined on two columns. and its type will have to be specified. The Custom Transaction and other transactions that will be developed in the future, do not require a primary key to be defined
$insertTNG1->setPrimaryKey("id_dep", "NUMERIC_TYPE");
Execute the transaction:
$tNGs->executeTransactions();
Get the Transaction Recordset. The dispatcher will search all registered transactions that are linked to the given table and will return the correct Recordset.
// Get the transaction recordset
$rsDepartments_dep = $tNGs->getRecordset("departments_dep");
$row_rsDepartments_dep = mysql_fetch_assoc($rsDepartments_dep );
$totalRows_rsDepartments_dep = mysql_num_rows($rsDepartments_dep );