June 2017
Intermediate to advanced
536 pages
9h 49m
English
Transactions with PDO are not much different from those with MySQLi. Utilizing the beginTransaction(), commit(), and rollback() methods of the PDO instance, we are able to control the transaction features of MySQLi:
<?php$conn = new PDO( "mysql:host=127.0.0.1;dbname=sakila", 'root', 'mL08e!Tq', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);try { // Start new transaction $conn->beginTransaction(); // Create new address $result = $conn->query('INSERT INTO address ( address, district, city_id, postal_code, phone, location ) VALUES ( "The street", "The district", 537, "27107", "888777666555", POINT(45.55111, 18.69389) ); '); // Fetch newly created address id $addressId = $conn->lastInsertId(); // Create new customer $statement ...
Read now
Unlock full access