doupa8922 2014-04-19 07:57 采纳率: 100%
浏览 33
已采纳

php / mysql查找和替换使用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 ?

  • 写回答

1条回答 默认 最新

  • douliao2493 2014-04-19 08:03
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效