Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OCI calls and database insert issue

Status
Not open for further replies.

cleanair4me

Technical User
May 16, 2008
61
I am using PHP 5.2.5 to insert record into Oracle 9i.

For my database input I was getting two duplicate record inserts when I only needed just one record.

Here is what I had:
Code:
require_once('oraConnect.php');
$query = "insert into cityTable values (1, 'George')";
$stmt = oci_parse($db_conn, $query);
oci_execute($stmt);

After commenting out the oci_execute($stmt) line it correctly inserted one record:
Code:
require_once('oraConnect.php');
$query = "insert into cityTable values (1, 'George')";
$stmt = oci_parse($db_conn, $query);
//oci_execute($stmt);

Please advise why the oci_execute($stmt) gave me multiple inserts? I thought I needed the oci_execute($stmt) to execute the insert but it seems that duplicates my database record insert so I eliminated that line and only need the $stmt = oci_parse($db_conn, $query) to insert 1 record.
 
something else is going on. oci_parse only prepares a query and returns a statement. it does not execute it.
so your code looks right to me.

but ...

i am surprised it is working at all to insert data as you are not supplying a query MODE. in the absence of a mode, php assumes you are using the default mode which is to run all queries as a transaction. thus you need to provide a commit/rollback explicitly.

Code:
require_once('oraConnect.php');
$query = "insert into cityTable values (1, 'George')";
$stmt = oci_parse($db_conn, $query);
if (oci_execute($stmt)){
 oci_commit($db_conn);
} else {
 oci_rollback($db_conn);
}

it may be that you are setting the execution mode in your oraConnect.php script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top