Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
I need to find and replace.
Old 01-28-2009, 01:34 AM I need to find and replace.
Webmaster Talker

Posts: 626
Trades: 0
I have a website that is powered by Joomla. I have just changed companies and I need to write a script that will search through all the tables of a given database and search ALL fields within each table. The script needs to find all occurances of "Old Company" and replace it with "New Company".

Can anyone help me out with this, I can't think of where to start and I need it done by tomorrow at the latest.

Any help would be appreciated.
jim.thornton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-28-2009, 02:50 AM Re: I need to find and replace.
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
The MySQL command to search all tables is: MYSQL SHOW FROM `db_name`
So when you have all the tables, I'd say you need to fetch the whole table and per row, check each field for 'Old Company' and if matched, replace and update that row in that table.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:04 AM Re: I need to find and replace.
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
This is easy only if you know exactly what table your old data is contained in... As in you could throw a mysql statement at your table like this. Note, this will replace everything in your joomla content table that contains one string with another string.

BACKUP YOUR DB before you do anything like this... I'm sure you know that but some people don't take that into consideration. Also, this is assuming you are using (jos_) as a table prefix for your joomla installation.

PHP Code:
UPDATE jos_content SET introtext REPLACE(introtext'oldcompany''newcompany'), fulltext REPLACE(fulltext'oldcompany''newcompany'); 
I think that should cover everything in your content, if not then look for component tables in your database and use the same mysql replace syntax to switch out your words.

Also, there is a sitename variable in your configuration file set to display the name of your website. I assume this is not pertinent, but just had to check.
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 08:46 AM Re: I need to find and replace.
Webmaster Talker

Posts: 626
Trades: 0
Thank you... I didn't realize that it would be so difficult. I need to change many instances of the words thorughout the whole site.

Forget about it. As I set, I thought I would be ablet do something like UPDATE * FROM * REPLACE(*, 'old company', 'new company), or something like that.

I just stayed up really late and did it manually.
jim.thornton is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I need to find and replace.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13652 seconds with 12 queries