#13914 closed defect (bug) (fixed)
select(databasename) fails in WP 3.0RC3
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (12)
#3
@
15 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;
#4
@
15 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
@
15 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
#7
@
15 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.
#9
@
15 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.
Broken in [12667].
$dbh should probably be an optional argument that defaults to $this->dbh.