每当我将WordPress复制到新位置时,我都会接管数据库修改器php脚本:
<?php
$database_host = \'\';
$database_user = \'\';
$database_pass = \'\';
$database_name = \'\';
$replacement_values = array( \'http://oldurl\' => \'http://newurl\' );
$text_fields = array( \'char\', \'text\', \'varchar\' );
$mysql = mysql_connect( $database_host, $database_user, $database_pass );
if ( !$mysql ) {
die( \'Could not connect: \' . mysql_error() );
}
$mysql_database = mysql_select_db( $database_name, $mysql );
if ( !$mysql_database ) {
die( \'Can\\\'t select database: \' . mysql_error() );
}
$tables_result = mysql_query( \'SHOW TABLES\' );
while ( $tables_row = mysql_fetch_row( $tables_result ) ) {
foreach ( $tables_row as $table ) {
$columns_result = mysql_query( \'SHOW COLUMNS FROM \' . $table );
while ( $columns_row = mysql_fetch_assoc( $columns_result ) ) {
$column = $columns_row[ \'Field\' ];
$type = $columns_row[ \'Type\' ];
foreach ( $text_fields as $text_field_type ) {
if ( strpos( $type, $text_field_type ) !== false ) {
echo \'<p>\' . $type . \' - \' . $column . \':\' . $table . \'</p>\';
foreach ( $replacement_values as $replace => $replacement ) {
$replace_query = sprintf( \'UPDATE %s SET %s = REPLACE(%s, \\\'%s\\\', \\\'%s\\\')\', $table, $column, $column, $replace, $replacement );
mysql_query( $replace_query );
}
break;
}
}
}
}
}
mysql_free_result( $columns_result );
mysql_free_result( $tables_result );
mysql_close ( $mysql );
?>
您可以在此处更改值:
$replacement_values = array( \'http://oldurl\' => \'http://newurl\' );
要替换的内容。