From: Chris on 16 Mar 2010 17:39 ZeYuan Zhang wrote: > Hi there. > > Why oci_commit function always returns true even when the transaction fails. > I just copied the code in the php manual [Example 1636. oci_commit() example], > and runned it, the situation is as follows: > > * The statements do commit at the moment when oci_commit executes. > * But some statements are committed to oracle successfully, when some fails. > I think it cannot be called a transaction, and I did used > OCI_DEFAULT in the oci_execute function. > > Code: > <?php > $conn = oci_connect('scott', 'tiger'); > $stmt = oci_parse($conn, "INSERT INTO employees (name, surname) VALUES > ('Maxim', 'Maletsky')"); > oci_execute($stmt, OCI_DEFAULT); Reading the docs (straight from http://www.php.net/manual/en/function.oci-commit.php). A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. You need to oci_execute($stmt, OCI_NO_AUTO_COMMIT); -- Postgresql & php tutorials http://www.designmagick.com/
From: Chris on 16 Mar 2010 18:54 Christopher Jones wrote: > > > Chris wrote: > > ZeYuan Zhang wrote: > >> Hi there. > >> > >> Why oci_commit function always returns true even when the transaction > >> fails. > >> I just copied the code in the php manual [Example 1636. oci_commit() > >> example], > >> and runned it, the situation is as follows: > >> > >> * The statements do commit at the moment when oci_commit executes. > >> * But some statements are committed to oracle successfully, when some > >> fails. > >> I think it cannot be called a transaction, and I did used > >> OCI_DEFAULT in the oci_execute function. > >> > >> Code: > >> <?php > >> $conn = oci_connect('scott', 'tiger'); > >> $stmt = oci_parse($conn, "INSERT INTO employees (name, surname) VALUES > >> ('Maxim', 'Maletsky')"); > >> oci_execute($stmt, OCI_DEFAULT); > > > > Reading the docs (straight from > > http://www.php.net/manual/en/function.oci-commit.php). > > > > A transaction begins when the first SQL statement that changes data is > > executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. > > > > You need to > > > > oci_execute($stmt, OCI_NO_AUTO_COMMIT); > > > > OCI_NO_AUTO_COMMIT is a recently introduced alias for OCI_DEFAULT, so > the original code is equivalent. This could be made clearer in the > oci_commit documentation, but is explained on > http://www.php.net/manual/en/function.oci-execute.php, which is where > the flag is actually used. Fair enough, thanks for the clarification :) -- Postgresql & php tutorials http://www.designmagick.com/
|
Pages: 1 Prev: oci_commit always returns true even when the transaction fails. Next: Calculator |