Just insert pg_exec($db,"BEGIN;"); after the connection is made and pg_exec($db,"COMMIT;"); when the process has completed successfully and pg_exec($db,"ROLLBACK;"); when the process fails. I believe it will rollback automatically if the script stops or the connection closes before a commit. Good luck. -jmb Sunit Sinha wrote: >Hi >i am using the postgres with php and updating and >inserting some data into db within the for loop. >as i want to implement the transection (BEGIN, COMMIT, >ROLLBACK) with it as these are sensetive data. So how >can i do it. i am also attaching my code so that it >can get a clear picture. > >How can i implement this with the below code. Please >help me. >with regards >Sunit > >###################################################### ><?php > $db= pg_connect("host=localhost dbname=abc >user=xyz password=123"); > > > $pkg_id1= $_POST["pkg_id"]; > echo $cp_id= $_POST["cp_id"]; > $id_total =count($pkg_id1); > $search_string=@$_POST['search_string']; > > $i = 0; > while ($i < $id_total) > { > $txt_pkg= "pgk_dis_".$pkg_id1[$i]; > $txt_pkg= $_POST[$txt_pkg]; > > if($txt_pkg==''|| $txt_pkg=='0') > { > next; > } > else > { > > $query_status = pg_exec($db,"select pkg_status from >pkg_master where pkg_id='$pkg_id1[$i]'"); > if(pg_result($query_status,0,"pkg_status")=='1') > { > next; > } > else > { > > > ####################### Updating the >pkg_cp_discount table ##################### > $query_count = pg_exec($db,"select cp_id, pkg_id >from pkg_cp_discount where cp_id= '$cp_id'and pkg_id= >'$pkg_id1[$i]'"); > $total_count = pg_numrows($query_count); > > if($total_count =='0') > { > $query = pg_exec($db,"insert into pkg_cp_discount >(pkg_price,cp_id, pkg_id) values('$txt_pkg', >'$cp_id','$pkg_id1[$i]')"); > } > else > { > $query_update = pg_exec($db,"update >pkg_cp_discount set pkg_price='$txt_pkg', >cp_id='$cp_id' where pkg_id='$pkg_id1[$i]'"); > } > } > } > > $i++; > > } >################################################## > >__________________________________________________ >Do You Yahoo!? >Tired of spam? Yahoo! Mail has the best spam protection around >http://mail.yahoo.com > > > >PHP Data object relational mapping generator - http://www.meta-language.net/ >Yahoo! Groups Links > > > > > > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/saFolB/TM --------------------------------------------------------------------~-> PHP Data object relational mapping generator - http://www.meta-language.net/ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-objects/ <*> To unsubscribe from this group, send an email to: php-objects-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/