Sunday, June 14, 2015

Committing PostgreSQL Transaction with PHP.

Committing PostgreSQL Transaction with PHP.

$constring = "host=localhost port=5432 dbname=yourdb user=youruser password=yourpassword"; 

$pglink = pg_connect($constring) or die('Could not connect');

pg_query("BEGIN") or die("Could not start transaction\n");

$user = pg_query("insert into users values(1, 'JJ')");
$staff = pg_query("insert into staffs values(1, 'JJ','Staff')"); 

if($user and staff){
       //Committing transaction
       pg_query("COMMIT") or die("Transaction commit failed\n"); 
      //Rolling transaction
       pg_query("ROLLBACK") or die("Transaction rollback failed\n"); 


The purpose of my posts is to keep the note of my works and, at the same time helping others. I hope this post will help someone.  Anything?? Please leave a comment. Good Luck!! ;)

No comments: