title: PHP Oracle transaction insert error
body: <p>I've wasted enough time on this and I need your help. It's probably a simple oversight but I use this function to connect to an oracle database a perform a transaction: </p>
  
  <pre><code>function transaction($query, $loop, $read_only, $return_vals){
       $DEBUG = 'yes';
  
      $db_name_idde = "server";
      $db_user_idde = "schema";
      $db_pass_idde = "password";
  
      $connection = oci_new_connect($db_user_idde, $db_pass_idde, $db_name_idde);
  
      $return_vars = array();
  
      //foreach always needs an array
      if( gettype($query) == 'string'){
          $query = array(0 =&gt; $query);
      }
  
      foreach($query as $statement){
  
          $stid = oci_parse($connection, $statement);
  
          if (!$stid &amp;&amp; $DEBUG == "yes") {
              die(oci_error($connection));
          } else if (!$stid) {
              die('Could Not Execute Query.');
          }
  
  
          if ( !oci_execute($stid, OCI_DEFAULT) &amp;&amp; $DEBUG == "yes") {
  
          // If we have a problem, rollback then die
              oci_rollback($connection);
              oci_close($connection);
  
              die($statement);
              //die(oci_error($stid));
          } else if ( !oci_execute($stid, OCI_DEFAULT) ) {
              oci_rollback($connection);
              oci_close($connection);
  
              die('Could Not Execute Query.');
          }
      }
  
      oci_commit($connection);
      oci_close($connection);
  
      // See if we need to send the results back
      if ($return_vals) {
          if ($loop) {
              $i = 0;
              while ($row = oci_fetch_array($stid, (OCI_RETURN_NULLS+OCI_ASSOC))) {
                  $return_vars[$i] = $row;
  
                  $i ++;
              }
          } else {
              $return_vars = oci_fetch_array($stid, (OCI_RETURN_NULLS+OCI_ASSOC));
          }
      } else {
          //$return_vars = mysql_insert_id($connection);
      }
  
      global $db_num_results;
      global $zero;
      $db_num_results = $i;
      $zero = 0;
  
      return $return_vars;
  }
  </code></pre>
  
  <p>Now this function can process Updates but always fails with inserts, INSERT INTO or INSERT ALL, <strong>claiming</strong> a duplicate key for the randomly generated OBJECTID. I started using mt_rand instead and it generates much longer IDs than anything in the DB so it shouldn't make this claim at all:</p>
  
  <pre><code>INSERT ALL
  
  INTO table1 (OBJECTID, OUTFALL_ID, INVESTIGATION_ID, LOGGED_DATE,LOGGED_BY,ASSET_ID,SOURCE,COMMENTS,STATUS, CREATED_BY, CREATED_DATE) 
  VALUES ( 1314897731, '10C10010', TO_CHAR(SYSDATE, 'YYYY') || '-' || sequence.NEXTVAL,  TO_DATE('05/15/2014','mm/dd/yyyy'),'person','','Sample','','Open', 'a@b.com', SYSDATE)
  
  INTO table2 (OBJECTID, OUTFALL_ID, INVESTIGATION_ID, TASK_DATE,TASK_TIME,ENTERED_BY,TASK_TYPE,DOCUMENT_LINK,SUMMARY, CREATED_BY, CREATED_DATE) 
  VALUES ( 1314897731, '10C10010', TO_CHAR(SYSDATE, 'YYYY') || '-' || sequence.CURRVAL,  TO_DATE('05/24/2014','mm/dd/yyyy'),'','person','Initial Inspection','','', 'a@b.com', SYSDATE) SELECT * FROM DUAL 
  </code></pre>
  
  <p>However when I run this statement in TOAD there aren't any complaints and there shouldn't be considering the new IDs I'm generating are at least 10x the size of the ones currently in there. Maybe I left some PL/SQL in there, or its accidentally repeating itself. I don't know.</p>