n00b0101
asked on
Mysql - Search for string in entire database
Is there a way to find a string through the whole database?
mysql_list_tables($dbname) will give you the names of every table in the database to which you are connected.
Do a while loop on that, and within the loop, for each table, mysql_list_fields($dbname, $tablename) will give you every fieldname in that table.
Do another while loop on that, and within this loop, do a SELECT $fieldname FROM $tablename WHERE $fieldname LIKE '%$string%'
Do a while loop on that, and within the loop, for each table, mysql_list_fields($dbname,
Do another while loop on that, and within this loop, do a SELECT $fieldname FROM $tablename WHERE $fieldname LIKE '%$string%'
I should say, if the former, then not really, no.
You could maybe do a SELECT .. UNION on *all* of your tables and then specify a WHERE clause with something like CONCAT(table1.col1, table1.col2, table2.col1, table2.col2, ...) LIKE "%string%"
Not fun to write that query and it will be horribly slow (well, depending on how many tables/columns you have).
You could maybe do a SELECT .. UNION on *all* of your tables and then specify a WHERE clause with something like CONCAT(table1.col1, table1.col2, table2.col1, table2.col2, ...) LIKE "%string%"
Not fun to write that query and it will be horribly slow (well, depending on how many tables/columns you have).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the latter, you can just do a mysqldump on your entire database and look through the results.
Open in new window