サンプル集 |
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■other |
Linuxコマンド |
用語集 |
debian メモ |
apache2 メモ |
MySQL メモ |
Oracle メモ |
HOME |
php で MySQL へ2つ接続しパラメータに従ってコミットを切り分けます。
◆環境OS | Windows XP Professional Version 2002 Service Pack 3 |
---|---|
PHP | 5.2.4 |
transaction_test.php | ||
|
まずは両方コミットを指定して実行します。
>php transaction_test.php 1 1
con1 コミット
con2 コミット
con1 コミット
con2 コミット
DB を確認します。
> select * from test_tbl;
+---------+--------+
| charVal | intVal |
+---------+--------+
| text10 | 10 |
| text11 | 11 |
| text12 | 12 |
| text13 | 13 |
| text14 | 14 |
| text15 | 15 |
| text16 | 16 |
| text17 | 17 |
| text18 | 18 |
| text19 | 19 |
| text20 | 20 |
| text21 | 21 |
| text22 | 22 |
| text23 | 23 |
| text24 | 24 |
| text25 | 25 |
| text26 | 26 |
| text27 | 27 |
| text28 | 28 |
| text29 | 29 |
+---------+--------+
20 rows in set (0.00 sec)
+---------+--------+
| charVal | intVal |
+---------+--------+
| text10 | 10 |
| text11 | 11 |
| text12 | 12 |
| text13 | 13 |
| text14 | 14 |
| text15 | 15 |
| text16 | 16 |
| text17 | 17 |
| text18 | 18 |
| text19 | 19 |
| text20 | 20 |
| text21 | 21 |
| text22 | 22 |
| text23 | 23 |
| text24 | 24 |
| text25 | 25 |
| text26 | 26 |
| text27 | 27 |
| text28 | 28 |
| text29 | 29 |
+---------+--------+
20 rows in set (0.00 sec)
ちゃんと 20件入っています。 次は、2つ目をロールバックに指定して実行します。
>php transaction_test.php 1 0
con1 コミット
con2 ロールバック
con1 コミット
con2 ロールバック
DB を確認します。 ・・・20件入っていました。 上手くロールバックできてないですね。
調べたところ、mysql_connect の4番目に true を指定しないと、新しいリンクを確立しないようです。 早速修正します。
transaction_test.php | ||
|
もう一度、2つ目をロールバックに指定して実行します。
>php transaction_test.php 1 0
con1 コミット
con2 ロールバック
con1 コミット
con2 ロールバック
DB を確認します。
>mysql select * from test_tbl;
+---------+--------+
| charVal | intVal |
+---------+--------+
| text10 | 10 |
| text11 | 11 |
| text12 | 12 |
| text13 | 13 |
| text14 | 14 |
| text15 | 15 |
| text16 | 16 |
| text17 | 17 |
| text18 | 18 |
| text19 | 19 |
+---------+--------+
10 rows in set (0.00 sec)
+---------+--------+
| charVal | intVal |
+---------+--------+
| text10 | 10 |
| text11 | 11 |
| text12 | 12 |
| text13 | 13 |
| text14 | 14 |
| text15 | 15 |
| text16 | 16 |
| text17 | 17 |
| text18 | 18 |
| text19 | 19 |
+---------+--------+
10 rows in set (0.00 sec)
できました。 ちゃんと2つ目の insert はロールバックされています。
Copyright (C) 2012 ymlib.com