Subject | Re: [firebird-php] How to capture exceptions? |
---|---|
Author | Jochem Maas |
Post date | 2005-05-25T17:55:20Z |
Thomas Beckmann wrote:
given that you used double quotes the $ should have been backslashed,
also the semi-colon is not needed.
I don't think firebird (is supposed to) 'throw' exceptions for this.
I have the following inside a custom DB class (written by the
guy who [re]wrote the firebird extension!)
$res = $dbg
? call_user_func_array('ibase_query', array_values($args))
: @call_user_func_array('ibase_query', array_values($args));
if (is_resource($res)) {
return new ResultSet($res);
} else {
if (!$res) {
throw new DBException(ibase_errcode(), ibase_errmsg());
} else {
return $res;
}
}
then in a test script I do (where sp_test is the same as your E_TEST_EX):
try {
//$r = DB::query('select 1/0 from rdb$database');
$r = DB::query('EXECUTE PROCEDURE sp_test');
var_dump($r);
}
catch(Exception $e) {
echo $e->__toString();
}
the output of ibase_errmsg() is what you need. for instance in my little test
it returned the following string:
"exception 8 GENCONF_NOT_DELETABLE"
where the word 'exception' is fixed, the number that follows it is the exception id
as defined in your DB and the last string is the exception 'value' (which I always
set to the same value as the name of the exception... and then let the application
translate however it sees fit)
NOTE:
none of the code aboves works as is (your missing about 25,000 lines which make up
the framework within which it runs!) but you should be able to figure it out
... you are among the firebird/php elite ;-)
good luck, if you do get stuck - come back, give more details and we/I will
try to help
(cheers btw, your question inspired me to actually delve into, and start using,
the firebird exception functionality via php -- I have had the relevant code for
about 18 months and have never bothered to use it :-/)
regards,
Jochem
> Hi everybody,I can't get "select 1/0 from rdb$database;" to cause an exception.
>
> as proposed by you, Lester and Jochem (thank you!), I switched to PHP5 [one
> strange thing - and hint to everybody: I needed to add: "gds_db 3050/tcp"
> to %windir%\system32\drivers\etc\services to get interbase.dll to work
> (thank you, Frank)], but actually, the described problem is still present -
> thus I kindly ask you - all of you, of course - for your knowledge again:
>
> The problem is that firebird exceptions (as raised by "select 1/0 from
> rdb$database;" or by this little script:
given that you used double quotes the $ should have been backslashed,
also the semi-colon is not needed.
I don't think firebird (is supposed to) 'throw' exceptions for this.
> "I can get this to work (i.e. trap the exception in php)....
> create exception E_TEST_EX 'Puff';
> set term ^ ;
> create procedure P_TEST_EX as begin exception E_TEST_EX; end ^
> set term ; ^
> execute procedure P_TEST_EX;
> ")
I have the following inside a custom DB class (written by the
guy who [re]wrote the firebird extension!)
$res = $dbg
? call_user_func_array('ibase_query', array_values($args))
: @call_user_func_array('ibase_query', array_values($args));
if (is_resource($res)) {
return new ResultSet($res);
} else {
if (!$res) {
throw new DBException(ibase_errcode(), ibase_errmsg());
} else {
return $res;
}
}
then in a test script I do (where sp_test is the same as your E_TEST_EX):
try {
//$r = DB::query('select 1/0 from rdb$database');
$r = DB::query('EXECUTE PROCEDURE sp_test');
var_dump($r);
}
catch(Exception $e) {
echo $e->__toString();
}
the output of ibase_errmsg() is what you need. for instance in my little test
it returned the following string:
"exception 8 GENCONF_NOT_DELETABLE"
where the word 'exception' is fixed, the number that follows it is the exception id
as defined in your DB and the last string is the exception 'value' (which I always
set to the same value as the name of the exception... and then let the application
translate however it sees fit)
NOTE:
none of the code aboves works as is (your missing about 25,000 lines which make up
the framework within which it runs!) but you should be able to figure it out
... you are among the firebird/php elite ;-)
good luck, if you do get stuck - come back, give more details and we/I will
try to help
(cheers btw, your question inspired me to actually delve into, and start using,
the firebird exception functionality via php -- I have had the relevant code for
about 18 months and have never bothered to use it :-/)
regards,
Jochem
> are silently ignored by PHP.
>
> I found some hints that adding an error_handler would do the trick but
> actually, this gets triggered on syntax errors only.
>
> Thus: Is there any way to capture firebird exceptions in PHP?
>
> Thank you for your hints!
>
>
> Thomas Beckmann wrote:
>
>>Hi Lester, hi Jochem,
>>
>>
>>>>>you may be using an older version of the extension... what
>>>>>version of php are you running this on (php4 perhaps)?
>>
>>Ok, I'll try php5.
>>
>>
>>>Unfortunately there are no plans to port any of the additions added in
>>>PHP5 back to the PHP4 builds. And any new work would be built on top of
>>>the PHP5 version.
>>>
>>>I have to admit that I've not tested the PHP5 version fully, but I
>>>currently get the errors I expect, and I'll have a try myself sometime.