954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Alter many files, all with same variable in them

I have 100's of files that access a field in a mySQL DataBase. I had to change the field name and now I have to update 100's of files. The files read:

$sql = 'SELECT user_id, username, user_colour, user_birthday FROM '

I need it to now read:

$sql = 'SELECT id, nick, user_colour, user_birthday FROM '


I know I could go through all files and execute a replace 'user_id' with 'id', but that would take forever. Does anyone know a program to do this easier?

woocha
Light Poster
48 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Off the top of my head, Dreamweaver has a search and replace (CTRL-F) function that will allow you to batch replace an entire folder/website/etc.

While you are finding and replacing, you might consider replacing 100 instances of the same code with an include path to a single script to make future revisions less painful.

johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
 

If you're on linux then grep is your friend. Also as Johnsquibb said, if you have probably over 5 instances of identical code, put it in one file then just include it.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

Off the top of my head, Dreamweaver has a search and replace (CTRL-F) function that will allow you to batch replace an entire folder/website/etc.

While you are finding and replacing, you might consider replacing 100 instances of the same code with an include path to a single script to make future revisions less painful.


Hey..that sounds like a good idea. Do you have any advise on how to get started with something like that

woocha
Light Poster
48 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You