Re: Problem with Oracle

From: Date: Wed, 25 Oct 2006 16:58:57 +0000
Subject: Re: Problem with Oracle
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-42595@lists.php.net to get a copy of this message
roy.a.jones@gsk.com wrote:
In Oracle you would write: insert into pts (pid, txt) values (1,'502a'); But in PHP you are going to do the following: $conn = oci_connect('scott','tiger','my_db'); $sql = "insert into pts (pid, txt) values (1,'502a')"; $cursor = oci_parse($conn, $sql); if (! $cursor) { $err = oci_error($conn); print htmlentities($e['message']); exit; } $results = oci_execute($cursor); oci_commit($conn); oci_close($conn);
The statements: $results = oci_execute($cursor); oci_commit($conn); do two commits. Oci_execute() commits by default. The message to the database to perform the commit is "piggybacked" in the execute call. However the subsequent (unecessary in this case) oci_commit() call requires an explicit round trip to the DB. If you were doing multiple inserts you might do something like: $s = oci_parse($c, 'insert into ptab (pdata) values (:bv)'); oci_bind_by_name($s, ':bv', $v, 20, SQLT_CHR); foreach ($a as $v) {
    $r = oci_execute($s, OCI_DEFAULT);
} oci_commit($c); Or explore calling a PL/SQL block and do a bulk FORALL insert. I'll blog about bulk FORALL in a few days. Chris -- Christopher Jones, Oracle Email: Christopher.Jones@oracle.com Tel: +1 650 506 8630 Blog: http://blogs.oracle.com/opal/

« previous php.db (#42595) next »