0

I understand how to use the Replace function in MySQL to replace strings of text but when I try something like this I get 0 records updated. What am I missing?

UPDATE `pages_description` 
    SET `pages_body` = REPLACE(`pages_body`, "pages.php?pID=16&CDpath=4", "pages.php?pID=188&CDpath=0_4")
0

2 Answers 2

1

It was the ampersand! OMG I needed to use the & entity for it. pages.php?pID=16&CDpath=4 I also wanted to point out (for future reference) that you will have to change the delimiter to an unused character in PhpMyAdmin to use as is. I changed mine to a colon instead of a semicolon. Example of delimiter location.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe it's not finding any matches? Make sure you have everything spelled correctly. You can do a search like this to see if you get any results for the contents you are trying to replace.

SELECT `pages_body` FROM `pages_description` WHERE `pages_body` LIKE '%pages.php?pID=16&CDpath=4%'

The replace function is also case sensitive, so check for that too.

3 Comments

It returns Zero results still, which doesn't make sense because I am looking right at the url in the source code and copy/ pasting.
What is the data type for the pages_body column? Also, can you copy paste a sample entry so I can test it on my end?
I figured it out, thank you. The Pages body was using the ampersand entity in place of an actual ampersand, which is why it was not finding any matches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.