[nycphp-talk] Searching an Entire MySQL Database
Matt Juszczak
matt at atopia.net
Thu Nov 4 16:16:35 EDT 2010
You could also do a mysqldump, find and replace with sed, then import.
------Original Message------
From: Dan Cech
Sender: talk-bounces at lists.nyphp.org
To: talk at lists.nyphp.org
ReplyTo: NYPHP Talk
Subject: Re: [nycphp-talk] Searching an Entire MySQL Database
Sent: Nov 4, 2010 09:29
On 11/4/2010 8:32 AM, ps at blu-studio.com wrote:
> I am wondering if anyone has had to search an entire database and do a search
> and replace on a string. That is to search in every table, in every row, in
> every field.
The simplest way will be to loop through the tables in php (use SHOW
TABLES), constructing & executing an UPDATE statement for each one like:
UPDATE table SET
field1=REPLACE(field1,'from','to'),
...
fieldN=REPLACE(fieldN,'from','to');
You can use DESCRIBE TABLE table; to get the list of fields, and to cut
them down to only the fields containing text based on the field type.
Dan
_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org/Show-Participation
More information about the talk
mailing list