objSQL Error Handling
Error handling is specific to each database type and is dependant on the current connection instance.
- Call the obj_error() method to test for an error.
Returns: False if no error or true on the last error.
- Call the obj_error_message() method to display or log an error message.
Returns: Verbose error message on the last error or null if no error.
<?php
try
{
$dbh = new objSQL( "mysql,localhost,root,pass,mydb,3306" );
if ( error_get_last() !== null )
throw new Exception( error_get_last()['message'] );
$rs = $dbh->obj_query( "delete from mytable where id=1" );
if ( $dbh->obj_error() )
throw new Exception( $dbh->obj_error_message() );
echo $rs->obj_affected_rows();
$dbh->obj_close();
}
catch ( Exception $e )
{
//log error and/or redirect user to error page
}
?>