WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#42776 closed defect (bug) (invalid)

WP(v.4.9.1) error in wp-db.php

Reported by: adminkov Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.1
Component: Query Keywords:
Focuses: Cc:
PR Number:

Description (last modified by dd32)

Working on my plugin, I found that when I send a request to
a database where there is one field empty - then WP (v.4.9.1) gives an
error and stop.
Example:

  1. my request:
    $sql = "INSERT INTO
    {$wpdb->prefix}watchman_site_cross_table (`date_country`, `tbl_country`,
    `tbl_result`) SELECT DATE_FORMAT(`time_visit`,'%Y %m') as `date_country`,
    LEFT(`country`,4) as `tbl_country`, COUNT(`user_ip`) as `tbl_result` FROM
    {$wpdb->prefix}watchman_site GROUP BY `date_country`, `tbl_country` ORDER
    BY `tbl_country` ";
    $wpdb->query($sql);
    
  2. The message in the admin panel:

Fatal error: Cannot access empty property in D:OpenServerdomainsadminkov.localwp-includes wp-db.php on line 1901
3.The reason for WP break is that the 'country' field is empty. Maybe this
will help you improve WP(v.4.9.1). Good luck.

Change History (4)

#1 follow-up: @dd32
2 years ago

  • Description modified (diff)
  • Keywords reporter-feedback added

Hi @adminkov,

Can you please verify the code needed to reproduce this?
With the code provided, being a INSERT it shouldn't have been running on line 1901 as that's for select-based queries. Was it indeed a SELECT query which you were running?

The code in question (The first large block deals with INSERT's, the second highlight is the line which triggered the fatal)
https://core.trac.wordpress.org/browser/tags/4.9.1/src/wp-includes/wp-db.php?marks=1877-1892,1901#L1874

Thanks!

#2 in reply to: ↑ 1 @adminkov
2 years ago

Replying to dd32:

Hi @dd32,
I want to help WP developers.

Now on the merits of the case:
When I received this error, I manually filled in the blank field "country" and the error was gone.
I attached to my answer a small file from my plugin that gave an error

Thanks!

https://www.adminkov.bcr.by/wordpress/error-plugin-wordpress/

#3 @adminkov
2 years ago

  • Resolution set to invalid
  • Status changed from new to closed

#4 @netweb
2 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.