Skip to content

No autocommit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
M737557 opened this issue Apr 4, 2025 · 1 comment
Open

No autocommit #1

M737557 opened this issue Apr 4, 2025 · 1 comment

Comments

@M737557
Copy link

M737557 commented Apr 4, 2025

My suggestion is, add to the sheet: No autocommit.

https://www.php.net/manual/en/pdo.commit.php
https://www.php.net/manual/en/pdo.begintransaction.php

$pdo = new PDO($dsn, $username, $password);

try {
// Start the transaction
$pdo->beginTransaction();

// Execute multiple queries
$pdo->exec("UPDATE accounts SET balance = balance - 100 WHERE user_id = 1");
$pdo->exec("UPDATE accounts SET balance = balance + 100 WHERE user_id = 2");

// Commit the transaction if all queries succeeded
$pdo->commit();

} catch (Exception $pdo) {
// Roll back the transaction if any query fails
$pdo->rollBack();
echo "Transaction failed: " . $pdo->getMessage();
}

@M737557
Copy link
Author

M737557 commented Apr 4, 2025

$db = pdo_connect_mysql(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION, PDO::ATTR_AUTOCOMMIT, 0); // 0 = false

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

No branches or pull requests

1 participant