[nycphp-talk] Searching an Entire MySQL Database
Dan Cech
dcech at phpwerx.net
Thu Nov 4 09:29:23 EDT 2010
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
More information about the talk
mailing list