Skip to content

Wrong information in comment at example #1 (Implicit Commit Example) #5488

@abdelrahman-gado

Description

@abdelrahman-gado

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
?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions