Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#13914 closed defect (bug) (fixed)

select(databasename) fails in WP 3.0RC3

Reported by: adiant's profile adiant Owned by: ryan's profile ryan
Milestone: 3.0 Priority: high
Severity: normal Version: 3.0
Component: Database Keywords: has-patch
Focuses: Cc:


The following php code (in page.php) fails in 3.0RC3, but works in 2.9.2:

global $wpdb;

$wpdb->show_errors = true;


ebrt_ebc is the name of a database where the WP database user ID has full access.

Messages as follows:

Warning: Missing argument 2 for wpdb::select(), called in /home/ebrt/public_html/wp30rc3/wp-content/themes/default2/page.php on line 20 and defined in /home/ebrt/public_html/wp30rc3/wp-includes/wp-db.php on line 738

Can’t select database

Attachments (2)

13914.patch (498 bytes) - added by sean212 13 years ago.
Work's fine:D
13914.diff (600 bytes) - added by ryan 13 years ago.

Download all attachments as: .zip

Change History (12)

#1 @nacin
13 years ago

  • Milestone changed from Unassigned to 3.0
  • Priority changed from normal to high

Broken in [12667].

$dbh should probably be an optional argument that defaults to $this->dbh.

#2 @nacin
13 years ago

  • Keywords needs-patch added

#3 @nacin
13 years ago

I have no idea why $dbh is getting passed by reference there. That would need to be removed in order to make it an optional argument.

Something like:

function select( $db, $dbh = null ) {
   if ( is_null( $dbh ) )
      $dbh = $this->dbh;

13 years ago

Work's fine:D

#4 @markjaquith
13 years ago

  • Owner set to ryan
  • Status changed from new to reviewing

All our instances of ->select() pass in the dbh. Thus the patch will have no effect on WP core. It will prevent errors in plugins that use ->select(). Looks good to my eyes. Ryan?

#5 @westi
13 years ago

  • Keywords has-patch added; needs-patch removed

Change looks sensible to me.

Can't find a specific reason for the reference passing here - only need would be for a replacement wpdb class which wrapped its database handles in classes rather than the connection references we get for mysql.

Looks like the reference passing has always been there in mu -

#6 @ryan
13 years ago

Default values for pass-by-reference parameters is not supported by PHP 4.

13 years ago

#7 @ryan
13 years ago

Patch tested with PHP 4 and 5. Setting a default value for a reference causes a parse error in PHP 4, so the parameter is no longer passed by ref.

#8 @ryan
13 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [15266]) Make dbh parameter to select optional for plugin back compat. Don't pass by ref to preserve PHP 4 support. fixes #13914

#9 @hakre
13 years ago

There should be no need to pass a PHP resource by reference anyway. Looks like an older flaw in the originating MU code safe to remove.

#10 @adiant
13 years ago

I just updated to last night's nightly build and it works perfectly!

Thank you so much.

Note: See TracTickets for help on using tickets.