in db there are custom table name like wp_wpdf_docs and want to change table name to wp_ccdm_docs
as i am using
$oldtable_name = $wpdb->prefix . "wpfd_docs";
$newtable_name = $wpdb->prefix . "ccdm_docs";
$rename= $wpdb->query("RENAME TABLE ".$oldtable_name ." TO " .$newtable_name);
is it right process?
in db there are custom table name like wp_wpdf_docs and want to change table name to wp_ccdm_docs
as i am using
$oldtable_name = $wpdb->prefix . "wpfd_docs";
$newtable_name = $wpdb->prefix . "ccdm_docs";
$rename= $wpdb->query("RENAME TABLE ".$oldtable_name ." TO " .$newtable_name);
is it right process?
Share Improve this question edited Jan 4, 2022 at 21:24 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jan 4, 2022 at 11:31 Kou WPKou WP 53 bronze badges 1- 1 Can't you test it locally to see if it works? The big question will be: Where is that table used? If the old name is referenced after the rename, that will run you into trouble. – kero Commented Jan 4, 2022 at 11:45
1 Answer
Reset to default 0Yes, you can use the query
function to rename tables.
global $wpdb;
$oldTable = $wpdb->prefix . "wpfd_docs";
$newTable = $wpdb->prefix . "ccdm_docs";
$renameOk = $wpdb->query("RENAME TABLE " . $oldTable . " TO " . $newTable);
if( $renameOk )
{
echo 'All good';
}else{
echo 'Failed to rename table. Last DB error: ' . $wpdb->last_error;
}