ludicrousdb icon indicating copy to clipboard operation
ludicrousdb copied to clipboard

$wpdb->suppress_errors() not supressing fatal errors during dbDelta()

Open dealer-solutions-gene opened this issue 3 years ago • 3 comments

After updating the "WP Offload Media" plugin I received this error

Fatal error: Uncaught mysqli_sql_exception: Table 'wordpress.wp_2217_as3cf_items' doesn't exist in /var/www/app/web/app/mu-plugins/ludicrousdb/ludicrousdb/includes/class-ludicrousdb.php:1481

I've tracked it down to a dbDelta() call where the following is being executed, which has been written to ignore failures by the looks of it, eg under the situation where the table doesn't exist, as dbDelta's job is to create or update db tables...

	// Fetch the table column structure from the database.
	$suppress    = $wpdb->suppress_errors();
	$tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
	$wpdb->suppress_errors( $suppress );

the fatal error is generated via the _do_query code in class-ludicrousdb.php

	if ( true === $this->use_mysqli ) {
		$result = mysqli_query( $dbh, $query );
	} else {
		$result = mysql_query( $query, $dbh );
	}

and my "local fix" is to wrap the above in try/catch restoring the check on suppress_errors as crudely as I can think to do it

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

dealer-solutions-gene avatar Jul 18 '22 22:07 dealer-solutions-gene

I'm facing this issue also! The fix is not doing enough. Is there any additional fix in progress?

thd-fox avatar Nov 09 '22 08:11 thd-fox

@thd-fox Given this project's last release was Dec 5, 2020 I think this one's dead 🤕

dealer-solutions-gene avatar Nov 09 '22 21:11 dealer-solutions-gene

@dealer-solutions-gene Do you know any other $wpdb scaling replacement? Better than HyperDB or this one?

thd-fox avatar Nov 10 '22 14:11 thd-fox