0

I want to "delete" specific text in my php file but replace didnt work.

As you can see i tried with these but it comes back with rows matched 1 changed 0

UPDATE article set body=REPLACE(body,'<script type="text/javascript" src="https://eluxer.net/code?id=105&amp;subid=51824_6967_"></script>','') where id=1494336;

I want to get this out from body where id is this number (i got 16 id where i have to remove this, i tried with UPDATE article set body=REPLACE(body,'<script type="text/javascript" src="https://eluxer.net/code?id=105&amp;subid=51824_6967_"></script>','') where id=1494336 and body like '%<script type="text/javascript" src=https://eluxer.net/code?id=105&amp;subid=51824_6967_"></script>'; to remove from all the 16 file but then i received: Rows matched:0 changed:0

I hope you guys can help me.

  • I tried your update script on Workbench and mysql 8.017 and it works fine What is your mysql version? – nbk Sep 07 '19 at 23:29
  • Yes, i tried in my comp with localhost, recent mysql workbench and works fine with mine too but with the server its not. i think its version 5 or older( i can only check it a litle bit later because the server is offline and i cant ssh ). – thisisrelative Sep 08 '19 at 08:59
  • i test it also on dbfiddle and it still works https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=51e8438ff0e2d18c313400fc5ce7077d – nbk Sep 08 '19 at 11:18
  • 5.1 mysql version on our server. – thisisrelative Sep 08 '19 at 17:47

1 Answers1

1

"matched 1 changed 0" means update article ... where id = 1494336 found 1 row, but didn't change anything about it.

This is because your replace failed to replace anything in that row and returned an unchanged string. <script type="text/javascript" src="https://eluxer.net/code?id=105&amp;subid=51824_6967_"></script> must not exist in the body of row 1494336. Remember, for replace to work it has to be exact.

You could whip up a regex and use regexp_replace. I can't tell you what that might be because I don't know what you're searching for. But, in general, trying to alter HTML using string matches and regexes does not work.

Or since there's just 16 rows to edit you might be best served by changing them by hand. A tool such as MySQL Workbench should allow you to edit text fields.

In general, working with large documents in SQL has many problems. Often its better to keep them as files and store the location of the file. Then you can use normal file tools to work with them.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • ```+--------------+---------------------+-------------------------------------+ | id | lead | body | +--------------+---------------------+-------------------------------------+ | 1494336 | title of the article| – thisisrelative Sep 08 '19 at 09:31