[wp-hackers] WPDB does not seem to support RENAME TABLE query

Paul Menard paul at codehooligans.com
Sat Sep 21 23:02:09 UTC 2013


Maybe I'm missing something. Or maybe this is just an oversight on the wpdb class. 

When calling the SQL RENAME TABLE `table_source` TO `table_dest`;

I get a PHP Warning: errno:2 mysql_fetch_object(): supplied argument is not a valid MySQL result resource /usr/local/www/htdocs/projects/Incsub/local.inc352-snapshot.com/wp-includes/wp-db.php on line 1225

In looking at the wp-db.php code I see where it checks if the query is create, alter, truncate, drop (line 1212). This of course falls through. 

I know I have some options

1. Do my own direct mysql to handle the rename - But I want to try and keep this within WP. Plus it would mean a new DB connection. 

2. Change the query from RENAME TABLE query to something like INSERT INTO `table_dest` SELECT * FROM `table_source`; DROP TABLE `table_source`; This also mean I need to add in the CREATE TABLE query. So seems like multiple steps instead of the clean RENAME TABLE. 

Anyone see what I'm missing? Is there are way to use RENAME TABLE within $wpdb ?

P-



More information about the wp-hackers mailing list