Finding a term in mysql database

one idea is to run a number of loops and query the db.

this mysql_search.php script tells you which table in a db has the match for the searched term. run the script in commandline, ie


// Config
$server = "localhost";
$username = "root";
$passwd = "";
$db = "moodle";
$searchTerm = "water_pics";
$log = "mysql_search.log";
mysql_connect($server, $username, $passwd);
$r = mysql_query("show tables");

while ($table = mysql_fetch_array($r, MYSQL_ASSOC)) {
  $r1 = mysql_query("show columns from ".$table['Tables_in_'.$db]);
  while ($col = mysql_fetch_array($r1, MYSQL_ASSOC)) {
    $r2 = mysql_query("Select * from ".$table['Tables_in_'.$db]." where ". $col['Field']." like '%$searchTerm%'");
    while ($match = mysql_fetch_array($r2)) {
        $str = "table(".$table['Tables_in_'.$db].") - First_column_id ($match[0]) - column_matched (". $col['Field'].")\n";
        echo $str;
        $fp = fopen($log, 'a+');
        fwrite($fp, $str);

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.