[wp-trac] [WordPress Trac] #23085: Calling $wpdb->query() when no connection exists causes mysql_error() to throw an error

WordPress Trac noreply at wordpress.org
Fri Jan 4 00:47:31 UTC 2013


#23085: Calling $wpdb->query() when no connection exists causes mysql_error() to
throw an error
------------------------------------+------------------------------
 Reporter:  mbijon                  |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Database                |     Version:  3.5
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |
------------------------------------+------------------------------
Changes (by kurtpayne):

 * cc: kurtpayne (added)


Comment:

 I'm worried how you're hitting this error condition.  Is this a stock
 setup?

 I can reproduce this by setting `$wpdb->dbh = 0` in a test case.

 If MySQL went away, I would suspect you'd get a different error, like `not
 a valid MySQL-Link resource`.

 As for the fix, I would suggest using `is_resource` otherwise you're back
 to where you started.  If `$wpdb->dbh` is set to 1, your first condition
 would pass, and you'd still get the above error.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23085#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list