WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13914 closed defect (bug) (fixed)

select(databasename) fails in WP 3.0RC3

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

Description

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

global $wpdb;

$wpdb->show_errors = true;

$wpdb->select("ebrt_ebc");

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 4 years ago.
Work's fine:D
13914.diff (600 bytes) - added by ryan 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 nacin4 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.

comment:2 nacin4 years ago

  • Keywords needs-patch added

comment:3 nacin4 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;

sean2124 years ago

Work's fine:D

comment:4 markjaquith4 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?

comment:5 westi4 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 - http://trac.mu.wordpress.org/changeset/81

comment:6 ryan4 years ago

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

ryan4 years ago

comment:7 ryan4 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.

comment:8 ryan4 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

comment:9 hakre4 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.

comment:10 adiant4 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.