Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created March 2, 2022 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/a7ab9aab5fba71bf1eb325cb8fc5d467 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/a7ab9aab5fba71bf1eb325cb8fc5d467 to your computer and use it in GitHub Desktop.
【PHP】How to use transaction 2
<?php
/* データベース接続のコードは省略 */
try {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
// ここでデータの保存などの処理を行います。
$pdo->commit();
} catch (Exception $e) {
$pdo->rollBack();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment