Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#13323 closed feature request (wontfix)

CUSTOM_USER_TABLE disables $wpdb->insert.

Reported by: hanifb's profile hanifb Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Database Keywords: close
Focuses: Cc:

Description

If you have a custom_user_table on a different database than your wordpress install, the $wpdb->insert stops functioning.

Example:

Wordpress is installed on database_1 and the custom user table is on database_2.

define('CUSTOM_USER_TABLE', 'database_2.prefix_users');


The insert code is in wp-includes/wp-db.php

$sql= "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";

As you clearly can see, the result will be

`database_2.prefix_users`

That of course breaks the sql query, Because you may have a

database_2.`prefix_users`

or

database_2.prefix_users

but you may not have the database name wrapped in single quotes.

Solution:

In both the $wpdb->_insert_replace_helper and $wpdb->update, insert this before the query.

if(strpos($table,'.') === false) {
	$table = "`$table`";
	} else {
	$table = "$table";
	}
$sql= "{$type} INTO $table (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";

Any comments?

Change History (6)

#1 @hanifb
14 years ago

  • Milestone changed from Unassigned to 3.0

#2 @westi
14 years ago

  • Milestone changed from 3.0 to Future Release
  • Severity changed from major to normal

This has always been the way with that define as far as I know.

This doesn't look like a new issue in 3.0

I'm not sure this is the intention of that define at all.

I'm also not convinced this is an area of code to touch this close to release.

#3 @nacin
14 years ago

  • Keywords close added; wpdb database custom user table removed
  • Type changed from defect (bug) to feature request

The tables are supposed to be in the same database for custom users and usermeta tables. We don't support multiple databases like this in wpdb and I'd be hesitant to make such a change as it may constrict us in the future with the precedent it sets. If you want to use multiple databases, I suggest you extend the wpdb class.

#4 @hanifb
14 years ago

Valid arguments.

The reason i belived this would be a good enhacement is that the networks easyily grow and it is hard to manage databases with several hundred tables, so if you have multiple networks for ex. network.com/large-sub-sites and blogger.network.com, on different databases you might want to have a single user table for easier management of users.

And WP clearly does supports this, but the only thing that breaks it is the single quote fetishism. Hope this doesent end up in the big "future-enhacement-trash".

#5 @nacin
14 years ago

If this really is the only thing preventing shared user tables from being used across databases, then I see it useful. But wpdb really doesn't support multiple databases out of the box, or at least it isn't supposed to. There are however plenty of database drop-ins that provide that functionality in far more robust ways.

#6 @nacin
12 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.