Jump to content


sql statement help


2 replies to this topic

#1 mattiedog

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 04 November 2009 - 06:05 PM

Hi

We moved our php/mysql database from one host to another.

After the move we notied our images were not showing up.

We need change the path to the images.

the table name is called "categories" the field we need to change is called "productImage"

in the productImage field we have a path like this http://www.domainnam...s/imagename.jpg

we need to change the path to
http://www.domainnam...s/imagename.jpg

I tried to create the sql statement and had to reload the database because i screwd up the field.

how do I replace all the path names in alll records that meet this criteria from domainname1 to domainname2 and leave the rest of the path the same.

Thanks in advanced

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 04 November 2009 - 10:22 PM

I've honestly not used the REPLACE command myself, but logically from what I've read this should do the trick for you. I'd make a backup before implementing it of course.

UPDATE `categories` SET `productImage` = REPLACE(`productImage`, 'domainname1.com', 'domainname2.com');

From what I read, it will replace the instances while leaving the rest unaffected as you want. <_<

As good practice, really on a site, you should use relative paths for files instead of absolute addresses in-case you need to move sites or something just like this. ;)

#3 mattiedog

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 05 November 2009 - 07:45 AM

hi John:

Thank you very much for responding to my question.

I will try it today and will let you know the outcome.

Steve





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users