@@ -735,7 +735,7 @@ public function query(string $sql, bool $showError = true)
735
735
736
736
if ($ showError ) {
737
737
$ gLogger ->critical ('PDOException: ' . $ exception ->getMessage ());
738
- $ this ->showError ();
738
+ $ this ->showError ($ exception -> getMessage (), $ exception -> getCode () );
739
739
// => EXIT
740
740
}
741
741
@@ -794,7 +794,7 @@ public function queryPrepared(string $sql, array $params = array(), bool $showEr
794
794
795
795
if ($ showError ) {
796
796
$ gLogger ->critical ('PDOException: ' . $ exception ->getMessage ());
797
- $ this ->showError ();
797
+ $ this ->showError ($ exception -> getMessage (), $ exception -> getCode () );
798
798
// => EXIT
799
799
}
800
800
@@ -929,31 +929,32 @@ private function setConnectionOptions()
929
929
* The error must be read by the child method. This method will call a backtrace, so
930
930
* you see the script and specific line in which the error occurred.
931
931
* @param string $errorMessage Optional an error message could be set and integrated in the output of the sql error.
932
+ * @param int $code Optional a code for the error be set and integrated in the output of the sql error.
932
933
* @return void Will exit the script and returns a html output with the error information.
933
934
* @throws Exception
934
935
*/
935
- public function showError (string $ errorMessage = '' )
936
+ public function showError (string $ errorMessage = '' , int $ code = 0 )
936
937
{
937
938
global $ gLogger , $ gSettingsManager , $ gL10n ;
938
939
940
+ if ($ errorMessage === '' ) {
941
+ // transform the database error to html
942
+ $ code = $ this ->pdo ->errorCode ();
943
+ $ errorMessage = $ this ->pdo ->errorInfo ()[2 ];
944
+ }
945
+
939
946
// Rollback on open transaction
940
947
if ($ this ->transactions > 0 ) {
941
948
$ this ->pdo ->rollBack ();
942
949
}
943
950
944
- // transform the database error to html
945
- $ errorCode = $ this ->pdo ->errorCode ();
946
- $ errorInfo = $ this ->pdo ->errorInfo ();
947
-
948
- $ gLogger ->critical ($ errorCode .': ' .$ errorInfo [1 ].' | ' .$ errorInfo [2 ]);
951
+ $ gLogger ->critical ($ code . ': ' . $ errorMessage );
949
952
950
953
$ htmlOutput = '
951
954
<div style="font-family: monospace;">
952
955
<p><strong>S Q L - E R R O R</strong></p>
953
- ' . $ errorMessage . '
954
- <p><strong>CODE:</strong> ' . $ errorCode . '</p>
955
- ' . $ errorInfo [1 ] . '<br /><br />
956
- ' . $ errorInfo [2 ] . '<br /><br />
956
+ <p> ' . $ errorMessage . '</p>
957
+ <p><strong>CODE:</strong> ' . $ code . '</p>
957
958
<strong>B A C K T R A C E</strong><br />
958
959
' . $ this ->getBacktrace () . '
959
960
</div> ' ;
0 commit comments