Skip to content

Fatal error for DB errors #156

@Yogurt4

Description

@Yogurt4
Fatal error: Uncaught TypeError: pg_fetch_assoc(): Argument #1 ($result) must be of type PgSql\Result, bool given in /var/www/html/wp-content/pg4wp/driver_pgsql.php:555 Stack trace: #0 /var/www/html/wp-content/pg4wp/driver_pgsql.php(555): pg_fetch_assoc(false) #1 /var/www/html/wp-content/pg4wp/core.php(34) : eval()'d code(2351): wpsqli_query(Object(PgSql\Connection), 'INSERT INTO `wp...') #2 /var/www/html/wp-content/pg4wp/core.php(34) : eval()'d code(2265): wpdb2->_do_query('INSERT INTO `wp...') #3 /var/www/html/wp-content/pg4wp/core.php(34) : eval()'d code(2614): wpdb2->query('INSERT INTO `wp...') #4 /var/www/html/wp-content/pg4wp/core.php(34) : eval()'d code(2503): wpdb2->_insert_replace_helper('wp_posts', Array, NULL, 'INSERT') #5 /var/www/html/wp-includes/post.php(4851): wpdb2->insert('wp_posts', Array) #6 /var/www/html/wp-includes/nav-menu.php(549): wp_insert_post(Array, true, true) #7 /var/www/html/wp-content/plugins/wordpress-importer/class-wp-import.php(1094): wp_update_nav_menu_item(51, 0, Array) #8 /var/www/html/wp-content/plugins/wordpress-importer/class-wp-import.php(1393): WP_Import->process_menu_item(Array) #9 /var/www/html/wp-content/plugins/wordpress-importer/class-wp-import.php(140): WP_Import->backfill_parents() #10 /var/www/html/wp-content/plugins/wordpress-importer/class-wp-import.php(78): WP_Import->import('/var/www/html/w...', Array) #11 /var/www/html/wp-admin/admin.php(365): WP_Import->dispatch() #12 {main} thrown in /var/www/html/wp-content/pg4wp/driver_pgsql.php on line 555

It happens because $result is not checked at the end of wpsqli_query and is passed on to pg_fetch_assoc.

From line 548, I suggest this block instead:

    if ($result !== false && false !== strpos($sql, "INSERT INTO") && false !== strpos($sql, "RETURNING")) {
        $matches = array();
        preg_match("/^INSERT INTO\s+`?([a-z0-9_]+)`?/i", $query, $matches);
        $tableName = $matches[1];
        $primaryKey = get_primary_key_for_table($connection, $tableName);
        $row = pg_fetch_assoc($result);

        $GLOBALS['pg4wp_ins_id'] = $row[$primaryKey];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions