[nycphp-talk] Replacing a string within many tables, unknown columns

Andrew M. Yochum andrew at
Fri Feb 14 11:12:30 EST 2003

Here's one way of accomplishing this...

1. Use mysql_list_tables to grab a list of tables.

2. Use mysql_list_fields + mysql_num_fields to grab a list of fields per table.

3. Use mysql_field_type to find the fields of the type you want to manipulate
(char, varchar, text, etc.)

3. Compile an update statement using the mysql "replace" function to perform
the search an replace. Something like:
    update thetable set data = replace(data,'old_string','new_string');

Another way might be to do a mysqldump of the DB, replace strings in that file,
and load the edited file into the production DB.

Hope that helps.


On Fri, 14 Feb 2003, Lynn, Michael  wrote:

> Wondering if anyones come across a similar problem... Probably more of a mysql question - but I'm trying to solve the problem using php.
> I need to be able to replace every occurance of a string in many tables, many columns.  The string appears in tables in various places and usually embedded in a string type or var type column... The
> string will not be the entire contents of the column so a replace won't work.
> Eg: my development database contains url links to the development web site.  When I copy the tables to production, I want to search and replace every occurance of the development urls with production
> urls throughout the entire database.
> Thanks in advance.
> Regards,
> Mike
> --- Unsubscribe at ---

Andrew Yochum
Digital Pulp, Inc.
andrew at

More information about the talk mailing list