I have use this function, its very simple and cute.
with IBM DB2
<?php
// you must set the connection first
if (odbc_error())
{
echo odbc_errormsg($conn);
}
// if you want to show the perfect error message
// then format it using string functions.
?>
Have a good day!