Find and replace strange symbols in my table
I am finding weird symbols appearing as a result of an import which went well apart from strange symbols.
I am trying to fin开发者_运维知识库d all references to
–
I would like it replaced with
'
This is what i tried, that failed:
update exp_channel_data set * = replace(*,'–',''');
update table_name set field_name = replace(field_name,'–',''');
Is the correct way to do it like you have sort of said above.
However, if you have only just imported, and not used any of the data yet, you would be better off just re-importing the data and changing the import settings to ensure the correct character set to get rid of the anomaly.
If you can run a php script, something like the following should work: It's not native SQL but it does automate the process. It does all tables and all fields. Obviously if you only want one table etc you can just alter the script (remove outer loop)
// Assuming you have connected to database
$dbname = "your_db"
$sql = "SHOW TABLES FROM $dbname";
$tresult = mysql_query($sql);
while ($trow = mysql_fetch_row($tresult)) {
$fresult = mysql_query("SHOW COLUMNS FROM {$trow[0]}");
if (mysql_num_rows($fresult) > 0) {
while ($frow = mysql_fetch_assoc($fresult)) {
mysql_query("UPDATE {$trow[0]} set {$frow['Field']} = replace({$frow['Field']},'–',''');");
}
}
}
精彩评论