ADG_REDIRECT_DML in Oracle Active Data Guard 19c

Oracle & PHP: Table with two CLOBs - inserting clobs via formular

if (!empty($_POST['name'])) {
$sql=$db->executeLob("
insert into table_test 
(
name,
col_clob_1,
col_clob_2
) 
values 
( 
'" . $_POST['name'] . "',
EMPTY(CLOB),
EMPTY(CLOB)
) 
RETURNING 
comment_1, comment_2 INTO :mylob_loc_1, :mylob_loc_2 ",$_POST['comment_1'],$_POST['comment_2']);
}
public function executeLob($sql,$lob1, $lob2) {
 
  if ($this->connection) {
   // Prepare the statement
   $stid = oci_parse($this->connection, $sql);
 
   if (!$stid) {
    $e = oci_error($this->connection);
    var_dump($e);
   }
   
   // Perform the logic of the query   
      
   // Creates an "empty" OCI-Lob object to bind to the locator
   $myLOB1 = oci_new_descriptor($this->connection, OCI_D_LOB);
   $myLOB2 = oci_new_descriptor($this->connection, OCI_D_LOB);
   
   // Bind the returned Oracle LOB locator to the PHP LOB object
   $a = oci_bind_by_name($stid, ":mylob_loc_1", $myLOB1, -1, OCI_B_CLOB);
   $b = oci_bind_by_name($stid, ":mylob_loc_2", $myLOB2, -1, OCI_B_CLOB);
   
   $r = oci_execute($stid,OCI_NO_AUTO_COMMIT);
   if (!$r) {
    $e = oci_error($stid);
    var_dump($e);
   }
      
   // Now save a value to the LOB
   if ((!$myLOB1->save($lob1)) || (!$myLOB2->save($lob2))) {
    // On error, rollback the transaction
    oci_rollback($this->connection);
   } else {
    // On success, commit the transaction
    oci_commit($this->connection);
   }
   
   // Free resources
   oci_free_statement($stid);
   $myLOB1->free();
   $myLOB2->free();
 
   return $r;
  }
 }

Comments