Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // source code PHP MySQL Control Transaction
- // trans.php
- /*
- DATABASE & TABLE
- create database test;
- use test;
- CREATE TABLE trans
- (
- id int not null auto_increment,
- item varchar(30) not null,
- quantity varchar(10) not null,
- primary key(id)
- );
- INSERT INTO trans (id,item,quantity) VALUES (NULL,'Computer','5');
- */
- function begin() { @mysql_query("BEGIN"); }
- function commit() { @mysql_query("COMMIT"); }
- function rollback() { @mysql_query("ROLLBACK"); }
- @mysql_connect("localhost","root", "--ipv6--") or die(mysql_error());
- @mysql_select_db("test") or die(mysql_error());
- $query = "INSERT INTO trans (id,item,quantity) values (null,'Baseball',4)";
- begin(); // transaction dimulai
- $result = @mysql_query($query);
- if(!$result)
- {
- rollback(); // transaction rolls back
- echo "you rolled back";
- exit;
- }
- else
- {
- commit(); // transaction berhasil di commit
- echo "your insertion was successful";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement