Receive Firebird Exception message in PHP

Asked

Viewed 259 times

0

My script PHP is not receiving the message from exceptions which are generated by Firebird. I have a class that connects to BD, runs sql and disconnects.

Debugging the script, I saw that the exception is being generated as the script is interrupted, but the message is not being received by PHP. To receive the exception am using ibase_errmsg(). The function of the class responsible for the execution of the sql is this:

function sql($host, $user, $pass, $query, $charset){
$this->connect($host, $user, $pass, $charset);
if ($this->conectou) {
    try {
        if ($this->result=ibase_query($query)){
            $this->disconnect($type);               
            return $this->result;
        } else {
            $errmsg = ibase_errmsg();
            //Debug
            echo $errmsg; //Nada esta mostrando aqui!!!
            $this->disconnect($type);
            throw new Exception($errmsg);
        }
    }
    catch (Exception $e) {
        echo $e->getMessage();
    }
  }
}

At first I thought the problem might be in ibase_errmsg(), but, the most intriguing is that running the same script with Apache, Exception is shown normally.

  • Server: Debian
  • Firebird: 2.5 superclassic
  • Web Server: Nginx
  • PHP: 5.4.45
  • PHP process: php-fpm
  • 1

    Change echo $errmsg; for var_dump($errmsg); to test.

  • changed but still no message. Thanks for the tip!

  • But something returns? NULL or FALSE or STRING "", Please be more clear, if I don’t have to ask you things punched, it complicates too much like this ;)

  • It does not return, actually goes straight through the block of the true condition, as if it had not occurred to exception.

  • As I suspected :D ... has nothing to do with generating Exception, the problem is in ibase_query($query), Tell me what to return if you add a var_dump like this $this->result = ibase_query($query);
var_dump($this->result);
if ($this->result !== false) {?

  • Returned this: resource(8) of type (interbase result)

  • Carlos this means that the query is correct, I believe and so will not fire the else.

  • @Guilhermenascimento, out of curiosity I discovered that the exception is only being generated if I make a insert, update or delete in procedure. Making select it does not generate the exception, must be because of suspend which it is necessary to have. As you quoted in the other answer, that the Firebird must be returning true even generating the exception. This could be a failure of Firebird, Is there another way around this?

Show 4 more comments

1 answer

1


Starting from version 5.0 of PHP the function ibase_query returns the number of lines if it is INSERT, DELETE and UPDATE, as explained in https://secure.php.net/manual/en/function.ibase-query.php#refsect1-Function.Ibase-query-returnvalues

Then you’d better use an ID like === or !== and to debug better I always recommend to use var_dump instead of echo so for example:

$this->result = ibase_query($query);

if ($this->result !== false) {
    $this->disconnect($type);               
    return $this->result;
} else {
    $errmsg = ibase_errmsg();

    //Debug
    var_dump($errmsg); //Nada esta mostrando aqui!!!

    $this->disconnect($type);
    throw new Exception($errmsg);
}
  • So, really you are right, but even changing to this condition is as if the database has not generated the error. I caught the same sql which is passed to the function and running directly in the database, the exception is generated normally. It wouldn’t be any settings in php that might be disabled? like some warning setting? Even to be sure, I changed the procedure to which the sql does the select putting only the exception to be generated.

  • To procedure was as follows: CREATE OR ALTER PROCEDURE SP_TEST_EXCEPT (
 id_cliente integer)
returns (
 oresult smallint)
as
begin
 exception ERRO_003;
end

Browser other questions tagged

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