简体   繁体   中英

php/mysql find&replace Using REPLACE

im trying to find and replace some string in all my rows in a database first i get all tables and loop through them and get all columns then i execute this query

           if ($column_name !== 'id')
           {
             $replcace_q = $database->query("UPDATE $table_name SET $column_name = REPLACE('$column_name','$old','$new')") or die($database->error);
           }

the loop is ok and i go to each table successfully but the result of executing the command is when it updates a column it replaces the content with the column name for example if column_name is username the content will change to username.

what am i doing wrong ?

Your query is good, but there is a single silly mistake in it.

if ($column_name !== 'id') { $replcace_q = $database->query("UPDATE $table_name SET $column_name = REPLACE($column_name,'$old','$new')") or die($database->error); }

try this one and check it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM