phpretard Posted July 13, 2008 Share Posted July 13, 2008 I know how to search a database according to table name. Is there a way to search the entire db? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 I guess you'd have to know the names of all your tables, or find out how to return all the names of the tables then run a loop and search them individual. Unless there is some other way, which I'm unsure of. Quote Link to comment Share on other sites More sharing options...
chronister Posted July 13, 2008 Share Posted July 13, 2008 Make a connection to the db, and select the db that you want to work with... then <?php $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_object($result)) { $tables[] = $row->Tables_in_DBNAME; }; print_r($tables); ?> There is your list of tables in an array.... note DBNAME.... you will have to include the name of the database that your accessing.... It apparently will not allow you to do an AS XXX clause with this... So once you have your table array, then you can either loop through it and run the query against 1 table at a time or you can implode them and return the string you need... $newString = implode(", ", $tables); This will create a string out of the array and separate the pieces with a comma which you can most likely just plug the variable into your query to get the result you want. Hope this gets you started in the right direction. Nate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.