Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trick to reset odbc_error()

Tags:

php

odbc

I've learnt that odbc_execute() does not always trigger a proper ODBC error when it returns FALSE (not at least with the Oracle driver) and I can't fully trust odbc_error() or odbc_errormsg(). This situation is easy to detect when there wasn't a previous error because odbc_error() returns an empty string. However, when it returns something I don't know whether it belongs to the last failed operation or it's a remain from a previous error.

The simplest solution would be to reset the odbc_error() and odbc_errormsg() functions when there's an error so next calls would start from scratch, but I couldn't find a supported way to do so. Can you figure out a way to do it?

Background: I'm enhancing a legacy app with a class that encapsulates database calls. That's why I need to make everything as generic as possible.

like image 872
Álvaro González Avatar asked Dec 21 '11 08:12

Álvaro González


1 Answers

it's not necesary to reset the function I solved in this way:

function foo($sql){
   $res = odbc_exec($this->dbconn, $sql);
   if (odbc_error () and $res===false ) {
       return $this->catchException(odbc_errormsg($this->dbconn));

   }
    return $res;
}
like image 66
vteran93 Avatar answered Nov 02 '22 05:11

vteran93