Created
March 22, 2013 14:44
-
-
Save mzaragoza/5221795 to your computer and use it in GitHub Desktop.
MYSQL FIND ANYTHING IN DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
define("mz_DB_USERNAME", "XXXXXX"); | |
define("mz_DB_PASSWORD", "XXXXXX"); | |
define("mz_DB_HOST", "XXXXXX"); | |
define("mz_DB_DATABASE", "XXXXXX"); | |
require_once('config.inc.php'); | |
require_once('__database_class.php'); | |
$db = new mz_database(); | |
//echo("<pre>"); | |
//print_r($db); | |
//echo("<hr>"); | |
$var = $_GET['var']; // Get Variable you are looking for | |
?> | |
<form name="find" method="get"> | |
<table> | |
<tr> | |
<td>Find <input type="text" name="var" value="<?= $var ?>"/></td> | |
<td><input type="submit" /></td> | |
</tr> | |
</table> | |
</form> | |
<table border="2"> | |
<? | |
$tables_unique = 0; | |
$tableO = ""; | |
if ($var){ // if there is something in that variable | |
echo( " <h1>$var Appears ib this places:</h1> <br />"); // Display Test | |
$sql = "show tables"; // SQL TO GET ALL TABLES NAMES | |
$data = $db->qArray($sql); // GET A LIST OF ALL TABLES AS A ARRAY | |
//echo("<pre>");print_r($data); | |
for ($i=0;$i< count($data);$i++){ // LOOK THE ARRAY | |
$table = $data[$i][0]; // GET THE TABLE NAME | |
//echo($table . "<br />"); | |
$sql ="show columns from $table"; // SQL TO GET ALL THE COLS IN THAT TABLE | |
$data2 = $db->qArray($sql); // GET A LIST OF ALL COLS IN A TABLE AS A ARRAY | |
$field = " "; // CLEAR THE FIELD VAR | |
for ($ii=0;$ii< count($data2);$ii++){ | |
$field .= $data2[$ii]['Field']; | |
$field .= " like '%$var%' "; | |
if ($ii != count($data2)-1){ | |
$field .= " OR "; | |
}//if ($ii != count($data2)-1){ | |
}//for ($ii=0;$ii< count($data2);$ii++){ | |
$sql = "SELECT * FROM $table WHERE $field"; | |
$data3 = $db->qArray($sql); | |
if($data3){ | |
for ($iii=0;$iii< count($data3);$iii++){ | |
for ($vi=0;$vi< count($data3[$iii]);$vi++){ | |
if (strstr($data3[$iii][$vi],$var)){ | |
$sql1 = "SELECT * FROM $table WHERE ". $data2[0][0] . " = " .$data3[$iii][0] ; | |
$sql2 = "SELECT * FROM $table WHERE ". $data2[$vi]['Field'] . " like '%" .$var."%'" ; | |
if ($tableO != $table){ | |
$tableO = $table; | |
$tables_unique = $tables_unique +1; | |
?> | |
<tr> | |
<td colspan="2"><h1>TABLE: <?= $table ?></h1></td> | |
</tr> | |
<? | |
} | |
?> | |
<tr> | |
<td colspan="2"><strong>Field:</strong> <?= $data2[$vi]['Field'] ?></td> | |
</tr> | |
<tr> | |
<td colspan="2"><strong>SQL Row:</strong> <?= $sql1 ?></td> | |
</tr> | |
<tr> | |
<td colspan="2"><strong>SQL Field:</strong> <?= $sql2 ?></td> | |
</tr> | |
<tr> | |
<td colspan="2"><strong>Output:</strong> <?= $data3[$iii][$vi] ?></td> | |
</tr> | |
<tr> | |
<td colspan="2"> </td> | |
</tr> | |
<? | |
}//if (strstr($data3[$iii][$vi],$var)){ | |
}//for ($vi=0;$vi< count($data3[$iii]);$vi++){ | |
}//for ($iii=0;$iii< count($data3);$iii++){ | |
//echo("<br><br>"); | |
//echo("<hr><hr>"); | |
}//if($data3){ | |
}//for ($i=0;$i< count($data);$i++){ | |
}//if ($var){ | |
?> | |
</table> | |
<?= $var ?> Appers in <?= $tables_unique ?> Tables<br /> | |
<form name="find" method="get"> | |
<table> | |
<tr> | |
<td>Find <input type="text" name="var" value="<?= $var ?>"/></td> | |
<td><input type="submit" /></td> | |
</tr> | |
</table> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment