Committing PostgreSQL Transaction with PHP.

Committing PostgreSQL Transaction with PHP.

<?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"); 
}
else
{
      //Rolling transaction
       pg_query("ROLLBACK") or die("Transaction rollback failed\n"); 
}

pg_close($pglink);
?>



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!! ;)

Popular posts from this blog

npm refusing to install as a dependency of itself

How to call javascript functions from VB.NET and using WebBrowser Control