使用ROLLBACK Transaction Control撤消对PHP中的数据所做的更改

时间:2016-03-09 13:53:30

标签: php sql database postgresql relational-database

我正在使用UPDATE查询通过其ID获取PostgreSQL数据库中的某一行,并在2分钟内添加到当前时间。我希望能够进行此临时更改,将信息回显给用户,然后ROLLBACK更改。在关闭数据库中的连接之前,我是否需要在PostgreSQL中使用某个函数来ROLLBACK更改:

  $countv = "00:02";
  $query =  " UPDATE test SET count = count+ '$countv' WHERE count_id= '1'";
  $query =  "ROLLBACK";

 $result = pg_query($query) or die('Query failed: ' . pg_last_error());

// Printing results in HTML
 echo "<table>\n";
 echo "These are the temporary class times ";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
    echo "\t\t<td>$col_value</td>\n";
 }
echo "\t</tr>\n";
}
 echo "</table>\n";


 // Free resultset
pg_free_result($result);


 // Closing connection
 pg_close($dbconn);

0 个答案:

没有答案