Good morning.
Here is a piece of code (beginner level) I've made
in order to search for text strings through all the
columns of all the tables of a given Database.
Of course the code could be changed in order to scan
all tables of all databases, but I didn't need such
a thing.
I hope it will be useful to someone...
$to_search_array = explode(" ",$to_search);
$to_search_num = sizeof($to_search_array);
for($a=0; $a < $to_search_num; $a++ ) {
$connect=mysql_connect("host","user","pass"
$tables=mysql_list_tables("db",$connect);
while($table_found=mysql_fetch_row($tables))
$table_array[] = $table_found[0];
for($h=0; $h < sizeof($table_array); $h++ ) {
$sql = "SELECT * FROM " . $table_array[$h] . " WHERE ";
$connect=mysql_connect("host","user","pass"
$fields = mysql_list_fields("db", $table_array[$h], $connect);
$columns = mysql_num_fields($fields);
for ($j = 0; $j < $columns; $j++) {
$col_name = mysql_field_name($fields, $j);
if($j == ($columns - 1)) {
$end_line = "";
} else {
$end_line = " OR ";
}
$sql .= $col_name . " LIKE '%" . $to_search_array[$a] . "%'" . $end_line;
}
$sql .= " ORDER BY ID ASC";
$db = mysql_connect("host", "user", "pass"
mysql_select_db("db",$db);
$result=mysql_query($sql,$db);
$num = mysql_num_rows($result);
$cur = 1;
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$ID = $row["ID"];
echo "
!RESULT HERE!--> $ID <br>
";
$cur++;
}
}
}
Here is a piece of code (beginner level) I've made
in order to search for text strings through all the
columns of all the tables of a given Database.
Of course the code could be changed in order to scan
all tables of all databases, but I didn't need such
a thing.
I hope it will be useful to someone...
$to_search_array = explode(" ",$to_search);
$to_search_num = sizeof($to_search_array);
for($a=0; $a < $to_search_num; $a++ ) {
$connect=mysql_connect("host","user","pass"
$tables=mysql_list_tables("db",$connect);
while($table_found=mysql_fetch_row($tables))
$table_array[] = $table_found[0];
for($h=0; $h < sizeof($table_array); $h++ ) {
$sql = "SELECT * FROM " . $table_array[$h] . " WHERE ";
$connect=mysql_connect("host","user","pass"
$fields = mysql_list_fields("db", $table_array[$h], $connect);
$columns = mysql_num_fields($fields);
for ($j = 0; $j < $columns; $j++) {
$col_name = mysql_field_name($fields, $j);
if($j == ($columns - 1)) {
$end_line = "";
} else {
$end_line = " OR ";
}
$sql .= $col_name . " LIKE '%" . $to_search_array[$a] . "%'" . $end_line;
}
$sql .= " ORDER BY ID ASC";
$db = mysql_connect("host", "user", "pass"
mysql_select_db("db",$db);
$result=mysql_query($sql,$db);
$num = mysql_num_rows($result);
$cur = 1;
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$ID = $row["ID"];
echo "
!RESULT HERE!--> $ID <br>
";
$cur++;
}
}
}