ODBC PHP / Oracle - UPDATE, INSERT, DELETE

Asked

Viewed 189 times

3

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

Would anyone know 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);
}
?>

1 answer

2


Some banks work in two-way transfers by default. If change (Insert/update/delete) is executed it is not 'practice' on time, it is pending until the commit.

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

$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 on autocommit by default, the function odbc_autocommit() does this leave your call right after creating the connection.

odbc_autocommit($conn, true);
  • Still can’t communicate with the database :( is there a way to know if the Query was executed by ODBC? Something like an Odbc_result? something like.

  • @Rafaelbrito odbc_commit() returns error or false?

  • I added Odbc_commit() below my code only, it did not return at all.

  • @Rafaelbrito does there if(odbc_commit($conn)){ echo 'sucesso'; }else { print_r(odbc_errormsg($conn));}

  • It returns 'success', but the database does not update. I reviewed the table, the syntax, in Oracle Development the syntax is performs normally. What else could it be?

  • @Rafaelbrito Before the first if put odbc_autocommit($conn, true); now you must save the change to the bank.

  • Odbc_exec($Conn, $Query), after the changes you have indicated to me, is locking the PHP page. It is not enough to generate the 'success' anymore'.

  • I did all the tests, Odbc_exec, when you pass a database syntax, it hangs the PHP page. I take a comma from $Query, and it runs normally. What causes Odbc_exec to crash?

  • @Rafaelbrito I’ll take a look here. Out of curiosity the extension of oracle pq vc does not use in place of odbc?

  • 1

    It was internal problem of the same server, ran straight what you indicated me. Thank you very much.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.