[wp-trac] [WordPress Trac] #13323: CUSTOM_USER_TABLE disables $wpdb->insert.

WordPress Trac wp-trac at lists.automattic.com
Mon May 10 16:37:04 UTC 2010


#13323: CUSTOM_USER_TABLE disables $wpdb->insert.
--------------------------+-------------------------------------------------
 Reporter:  hanifb        |       Owner:  ryan                           
     Type:  defect (bug)  |      Status:  new                            
 Priority:  normal        |   Milestone:  Unassigned                     
Component:  Database      |     Version:  3.0                            
 Severity:  major         |    Keywords:  wpdb database custom user table
--------------------------+-------------------------------------------------
 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?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13323>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list