Receive Firebird exception message in PHP

0

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

By debugging the script, I saw that exception is being generated because the script is broken, but the message is not being received by PHP . To receive exception I'm using ibase_errmsg() . The function of the class that is responsible for executing 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 most intriguing is that running the same script with Apache, the exception is normally displayed.

  
  • Server: Debian
  •   
  • Firebird: 2.5 superclassic
  •   
  • Web Server: Nginx
  •   
  • PHP: 5.4.45
  •   
  • PHP process: php-fpm
  •   
    
asked by anonymous 20.01.2017 / 00:00

1 answer

1

Starting PHP version 5.0, the ibase_query function returns the number of rows if it is INSERT , DELETE and UPDATE , as explained in link

So it's better to use an ID like === or !== and to debug better I always recommend using 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);
}
    
20.01.2017 / 00:31