ODBC PHP / Oracle – UPDATE, INSERT, DELETE

Question:

I'm on a project using PHP and Oracle. the connection is OK, with this code I can execute all the selects I normally need, what I can't execute are INSERTS , UPDATES and DELETE .

Could anyone tell me why?

<?php
require_once('connection.php');
if($conn)
{
   $Query = "UPDATE PQAQ SET CAMINHO_ARQUIVO = 'PDF' WHERE CODIGO_PROCESSO = 18 AND CAMINHO_ARQUIVO = 'TESTE.PHP'";
   odbc_exec($conn, $Query);
}
?>

Answer:

Some banks work with two-phase delay by default. If the change (insert/update/delete) is executed, it is not put into 'practice' at the time, it remains pending until the commit.

There are two ways to solve this problem. The first is to submit the commit manually with the odbc_commit() function.

$Query = "UPDATE PQAQ SET CAMINHO_ARQUIVO = 'PDF' 
          WHERE CODIGO_PROCESSO = 18 AND CAMINHO_ARQUIVO = 'TESTE.PHP'";
odbc_exec($conn, $Query);

if(!odbc_commit($conn)){
    echo 'erro: '. odbc_errormsg($conn);
}

The second is to let odbc work in autocommit by default, the odbc_autocommit() function does this and leaves its call right after the connection is created.

odbc_autocommit($conn, true);
Scroll to Top