3

I am working on a MySQL based project, in which I have 57 tables in my database. I need to find table/tables and field from database on basis of stored data.

I want to describe my problem here.

Let I have data "value1" in a field in one of 57 tables of my database, I just know there is data "value1" somewhere in my database, now on basis of "value1" I want to find out

1) Which table "value1" exist. 2) For which field this data is been stored.

I am hopeful you got things I am looking for. Thanks in advance :)

ankit.jbp
  • 92
  • 1
  • 3
  • 9
  • Have you tried something? Do you want to do it all in MySQL or with Java/C#/.NET/... ? – araknoid Mar 01 '13 at 07:48
  • 1
    http://stackoverflow.com/questions/639531/mysql-search-in-all-fields-from-every-table-from-a-database – Deadlock Mar 01 '13 at 07:53
  • @araknoid I am working on a CMS based upon PHP and MSQL, actually there is very less support available to working on CMS,so am trying to find out things how it's workflow. – ankit.jbp Mar 01 '13 at 07:56
  • @Deadlock thanks :) to still I am having bit confusion will let know you if i'd have any query – ankit.jbp Mar 01 '13 at 07:57

1 Answers1

3

You should take a look at below link.

http://code.google.com/p/anywhereindb/

OR

<?php  
    $search_word = 'new.example.com';
    mysql_connect($host, $username, $password);

    $connection = mysql_connect('localhost','root','')or die(mysql_error());
    $database   = mysql_select_db('stackoverflow')or die(mysql_error());

    $sql = "SHOW TABLES FROM stackoverflow";
    $tables_result = mysql_query($sql)or die(mysql_query());



    echo "Look for '$search_word'\n\n";
    while ($table = mysql_fetch_row($tables_result))
    {
        echo "Table: {$table[0]}\n";
        //serach query for tables $table[0]     
    }
    mysql_free_result($tables_result);  
?>

use mysqli_* or PDO because mysql_* is deprecated.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
  • 1
    You can add a loop on mysql_fetch_field in the mysql_fetch_row loop, in order to lookup for the field name. – djleop Mar 01 '13 at 08:00
  • 1
    @djleop yes we can i just put much effort to gave him solution if i wrote every code for him then OP will not learn anything..my best try for answering is let OP to learn by himself.. – Dipesh Parmar Mar 01 '13 at 08:03
  • me too looking to develop my skills – ankit.jbp Mar 01 '13 at 08:21