Description
Transaction represent a “block” or “unit” of code that consists of multiple queries that are somehow related to one another.
and you might want to ensure that all queries have executed successfully BEFORE you commit the changes to the database.
Example: The second query should not be executed if the first query fails. allows to drop a table from database by specifying the table name.
You can start and commit transaction easily using PDOModel, you need to call beginTransaction and commitTransaction
Function Defination
$pdomodel->dbTransaction = true;//start transactions
$pdomodel->commitTransaction();//commit transaction
Examples
$pdomodel = new PDOModel(); //create object of the PDOModel class
$pdomodel->connect("localhost", "root", "", "pdocrud");//connect to database
/* PDO Transaction block */
$pdomodel->dbTransaction = true;//start transactions
$insertData = array("orderNumber"=>909, "customerName"=>"one", "address"=>"140 shakti nagar");
$pdomodel->insert("orderTable", $insertData);
$insertData = array("orderNumber"=>90099, "customerName"=>"two", "address"=>"140 shakti nagar");
$pdomodel->insert("orderTable", $insertData);
$pdomodel->commitTransaction();//commit transaction
Result/Output
Return true if table dropped successfully
Debug
| Option | Details | Example |
|---|---|---|
| $pdomodel->getLastQuery(); | Return last query executed | DROP TABLE `tablename` |
| print_r($pdomodel->error) | Print errors (if any) |