Permalink
Browse files

Support MySQL error codes in DB exceptions (#1315)

  • Loading branch information...
peterkeung authored and andrerom committed Oct 17, 2017
1 parent e806087 commit 7d92d36e12e434d23e50b2146238690b5f9e4be9
Showing with 27 additions and 1 deletion.
  1. +25 −0 kernel/private/classes/exceptions/database/exception.php
  2. +2 −1 lib/ezdb/classes/ezmysqlidb.php
@@ -17,5 +17,30 @@
*/
class eZDBException extends ezcBaseException
{
/**
* Original message, before escaping
*/
public $originalMessage;
/**
* Constructs a new eZDBException with $message and $code
*
* @param string $message
* @param int $code
*/
public function __construct( $message, $code = 0 )
{
$this->originalMessage = $message;
$this->code = $code;
if ( php_sapi_name() == 'cli' )
{
$this->message = $message;
}
else
{
$this->message = htmlspecialchars( $message, ENT_QUOTES, 'UTF-8' );
}
}
}
?>
@@ -404,7 +404,8 @@ function query( $sql, $server = false )
}
else
{
$errorMessage = 'Query error (' . mysqli_errno( $connection ) . '): ' . mysqli_error( $connection ) . '. Query: ' . $sql;
$this->setError();
$errorMessage = 'Query error (' . $this->ErrorNumber . '): ' . $this->ErrorMessage . '. Query: ' . $sql;
eZDebug::writeError( $errorMessage, __CLASS__ );
$oldRecordError = $this->RecordError;
// Turn off error handling while we unlock

0 comments on commit 7d92d36

Please sign in to comment.