19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPでトランザクション

Last updated at Posted at 2013-05-16

CakePHPでトランザクションを使う方法をネットで検索したところ、
古いバージョンばかりヒットするのでメモしておきます。

AppModel.phpに下記を追記します。

function begin() {
	$dataSource = $this->getDataSource();
	$dataSource->begin($this);
}

function commit() {
	$dataSource = $this->getDataSource();
	$dataSource->commit($this);
}

function rollback() {
	$dataSource = $this->getDataSource();
	$dataSource->rollback($this);
}

あとは、使いたい箇所で下記のようにするだけです。

$this->Model->begin();
19
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?