Skip to content

Commit

Permalink
Improve last error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Aug 13, 2024
1 parent d8f68ef commit 2509efa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ public function query( $query ) {
}

$this->result = $this->ex_mysql_query( $query, $this->dbh );

Check warning on line 963 in db.php

View workflow job for this annotation

GitHub Actions / Run code style check

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
$this->last_error = $this->ex_mysql_error( $this->dbh );

if ( $statement_after_query ) {
$query_for_log = "$query_for_log; $statement_after_query";
Expand All @@ -969,11 +970,12 @@ public function query( $query ) {
$elapsed = $this->timer_stop();
++$this->num_queries;

if ( preg_match( '/^\s*SELECT\s+SQL_CALC_FOUND_ROWS\s/i', $query ) ) {
if ( preg_match( '/^\s*SELECT\s+SQL_CALC_FOUND_ROWS\s/i', $query ) && false !== $this->result ) {
if ( false === strpos( $query, 'NO_SELECT_FOUND_ROWS' ) ) {
$this->timer_start();
$this->last_found_rows_result = $this->ex_mysql_query( 'SELECT FOUND_ROWS()', $this->dbh );
$elapsed += $this->timer_stop();
$this->last_error = $this->ex_mysql_error( $this->dbh );
++$this->num_queries;
$query .= '; SELECT FOUND_ROWS()';
}
Expand All @@ -996,8 +998,6 @@ public function query( $query ) {
}
}

$this->last_error = $this->ex_mysql_error( $this->dbh );

if ( $this->last_error ) {
$this->last_errno = $this->ex_mysql_errno( $this->dbh );
$this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] = $this->last_errno;
Expand Down

0 comments on commit 2509efa

Please sign in to comment.