Skip to content

Commit

Permalink
Add Try/Catch to: _do_query() (#154)
Browse files Browse the repository at this point in the history
This allows errors to be explicitly suppressed when a query fails.

Fixes #139.
  • Loading branch information
JJJ authored Apr 23, 2024
1 parent 547e91a commit 59aeaf3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ludicrousdb/includes/class-ludicrousdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -1553,10 +1553,18 @@ protected function _do_query( $query, $dbh_or_table = false ) { // phpcs:ignore
return false;
}

if ( true === $this->use_mysqli ) {
$result = mysqli_query( $dbh, $query );
} else {
$result = mysql_query( $query, $dbh );
try {
if ( true === $this->use_mysqli ) {
$result = mysqli_query( $dbh, $query );
} else {
$result = mysql_query( $query, $dbh );
}
} catch ( Throwable $exception ) {
if ( true === $this->suppress_errors ) {
$result = false;
} else {
throw $exception;
}
}

// Maybe log last used to heartbeats
Expand Down

0 comments on commit 59aeaf3

Please sign in to comment.