Welcome to WebmasterWorld Guest from 54.147.217.76

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Seeking for MySQL tables by regex

There's got to be a way to do this, but I can't find it

   
12:39 am on Apr 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a MySQL database with a little over 400 tables in it. I'm writing a script that needs to access about ten of these. The trouble is that those ten tables have what you might call dynamic titles, meaning they're created by other scripts periodically. This means I can't just hard-code the table names into my current script.

The tables in question do follow a consistent naming scheme - specifically, a three-letter word (they share the same one), followed by a random, unique, nine-digit number. No other tables in the database share this naming pattern.

How can I use PHP to scan the database for all tables that fit that pattern, without causing too much overhead?

Thanks in advance,

Matthew

1:38 am on Apr 3, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I was able to do this successfully:
SHOW TABLES WHERE Tables_in_database_name REGEXP '^f.*'

And I got the table names starting with f.
Alternatively you could use show tables to get them all into an array to regex them.

12:00 pm on Apr 3, 2008 (gmt 0)

5+ Year Member



when these dynamicly created tables are created just insert a row into a table that tracks thease dynamicly created tables.

have some sproc's that handle the dymincly created tables and handels the inserts/deletes etc