Skip to content

fix: change INSERT to be DROP in implicit commit example 1#5489

Closed
abdelrahman-gado wants to merge 1 commit intophp:masterfrom
abdelrahman-gado:fix/issue-5488
Closed

fix: change INSERT to be DROP in implicit commit example 1#5489
abdelrahman-gado wants to merge 1 commit intophp:masterfrom
abdelrahman-gado:fix/issue-5488

Conversation

@abdelrahman-gado
Copy link
Copy Markdown
Contributor

@abdelrahman-gado abdelrahman-gado commented Apr 13, 2026

Issue link => #5488

From manual page: https://php.net/pdo.transactions


in the Example 1 Implicit Commit Example

<?php
$pdo->beginTransaction();
$pdo->exec("INSERT INTO users (name) VALUES ('Rasmus')");
$pdo->exec("CREATE TABLE test (id INT PRIMARY KEY)"); // Implicit COMMIT occurs here
$pdo->rollBack(); // This will NOT undo the INSERT/CREATE for MySQL or Oracle
?>

The comment in the last line $pdo->rollback(); explains that we cannot undo the INSERT and this is wrong.
we can undo the INSERT but we cannot undo the create or drop (DDL) statements, So it should be like this

<?php
$pdo->beginTransaction();
$pdo->exec("INSERT INTO users (name) VALUES ('Rasmus')");
$pdo->exec("CREATE TABLE test (id INT PRIMARY KEY)"); // Implicit COMMIT occurs here
$pdo->rollBack(); // This will NOT undo the DROP/CREATE for MySQL or Oracle
?>

@kamil-tekiela
Copy link
Copy Markdown
Member

There is no DROP in that example. The comment is correct https://phpize.online/sql/mysql80/2521aa89a15e10f3e4cecaac6065540a/php/php84/385caba4a7d1ffaa8c6d497709ff188c/

Maybe it's a bit confusing that the slash is used there, but it means that neither the INSERT nor the CREATE can be rolled back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants