RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

10 June 09

[PHP-MySQL] MySQL transaction with PHP

// require MySQL Version 4.0.12 using InnoDB type tables.
@mysql_connect("localhost","username", "password") 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 begins
$result = @mysql_query($query);
if(!$result) {
	rollback(); // transaction rolls back
	echo "you rolled back";
	exit;
} else {
	commit(); // transaction is committed
	echo "Aggiornamento completato";
}

via DevArticles

See also:
Comments (View)
Themed by Hunson. Originally by Josh