From 43cba01c4915997785c7c56ee81674679b7a11ef Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 10 Nov 2022 14:38:51 +1000 Subject: [PATCH 1/3] Attempt to call `wpdb::set_sql_mode()` for compatibility with modern versions of MySQL. --- db.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/db.php b/db.php index 4239cf2..e80f631 100644 --- a/db.php +++ b/db.php @@ -435,6 +435,12 @@ public function db_connect( $query = '' ) { if ( ! $this->ex_mysql_select_db( DB_NAME, $this->dbh ) ) { return $this->log_and_bail( 'We were unable to select the database' ); } + + // Set the SQL mode + if ( is_callable( $this, 'set_sql_mode' ) ) { + $this->set_sql_mode(); + } + if ( ! empty( $this->charset ) ) { $collation_query = "SET NAMES '$this->charset'"; if ( ! empty( $this->collate ) ) { @@ -773,7 +779,12 @@ public function db_connect( $query = '' ) { $this->set_charset( $this->dbhs[ $dbhname ], $charset, $collate ); - $this->dbh = $this->dbhs[ $dbhname ]; // needed by $wpdb->_real_escape() + $this->dbh = $this->dbhs[ $dbhname ]; // needed by $wpdb->_real_escape() and `$wpdb->set_sql_mode()` + + // Set the SQL mode + if ( is_callable( $this, 'set_sql_mode' ) ) { + $this->set_sql_mode(); + } $this->last_used_server = compact( 'host', 'user', 'name', 'read', 'write' ); From 3b57cd0be11cdaa61497d901091d29bdbec5cb16 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 1 Feb 2023 11:32:25 +1000 Subject: [PATCH 2/3] Correct the syntax for `is_callable()`. Co-authored-by: Viktor Haid <52320564+viktorhaid@users.noreply.github.com> --- db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db.php b/db.php index e80f631..68f18c5 100644 --- a/db.php +++ b/db.php @@ -782,7 +782,7 @@ public function db_connect( $query = '' ) { $this->dbh = $this->dbhs[ $dbhname ]; // needed by $wpdb->_real_escape() and `$wpdb->set_sql_mode()` // Set the SQL mode - if ( is_callable( $this, 'set_sql_mode' ) ) { + if ( is_callable( array($this, 'set_sql_mode') ) ) { $this->set_sql_mode(); } From 0669ea1e0fee5dc59b1d3b848824d9188b13d837 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 1 Feb 2023 11:35:11 +1000 Subject: [PATCH 3/3] Formatting cleanup. --- db.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db.php b/db.php index 68f18c5..4421cf6 100644 --- a/db.php +++ b/db.php @@ -436,8 +436,8 @@ public function db_connect( $query = '' ) { return $this->log_and_bail( 'We were unable to select the database' ); } - // Set the SQL mode - if ( is_callable( $this, 'set_sql_mode' ) ) { + // Set the SQL mode. + if ( is_callable( array( $this, 'set_sql_mode' ) ) ) { $this->set_sql_mode(); } @@ -781,8 +781,8 @@ public function db_connect( $query = '' ) { $this->dbh = $this->dbhs[ $dbhname ]; // needed by $wpdb->_real_escape() and `$wpdb->set_sql_mode()` - // Set the SQL mode - if ( is_callable( array($this, 'set_sql_mode') ) ) { + // Set the SQL mode. + if ( is_callable( array( $this, 'set_sql_mode' ) ) ) { $this->set_sql_mode(); }