Help - Search - Members - Calendar
Full Version: sql statement help
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
mattiedog
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.domainname1.com/productsimages/imagename.jpg

we need to change the path to
http://www.domainname2.com/productsimages/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
Demonslay
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.

CODE
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. smile.gif

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. bigwink.gif
mattiedog
hi John:

Thank you very much for responding to my question.

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

Steve
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.