[wp-trac] [WordPress Trac] #42776: WP(v.4.9.1) error in wp-db.php

WordPress Trac noreply at wordpress.org
Sun Dec 3 07:49:35 UTC 2017


#42776: WP(v.4.9.1) error in wp-db.php
-------------------------------+------------------------------
 Reporter:  adminkov           |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Query              |     Version:  4.9.1
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------
Changes (by dd32):

 * keywords:   => reporter-feedback


Old description:

> 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.

New description:

 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.

--

Comment:

 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!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42776#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list