every table MySQL Search fields from MySQL database

every table MySQL Search fields from MySQL database

in this post we will show you how to every table MySQL Search fields from MySQL database. This is pretty cool, if you wish to look for a text string all told fields of all tables of a MySQL information, you’ll be able to use phpMyAdmin to try to to this terribly simply. but if have to search with mysql query.

if you have to find mysql stored procedure,search in all databases,search procedure,all tables,all table all columns, find in tables mysql, stored procedure, Search in all fields from every table of a MySQL database , and there a mySQL query to search all tables intervals a database? For that problem solusion is hear by using this code Search through all databases.

If not can you search all tables within a database from the mySQL workbench GUI?

From phpmyadmin there is a search panel you’ll use to pick out all tables to look through. I notice this super effective since magento, the ecommerce package i am operating with has many tables and totally different product details are in numerous tables.

if we want to search in all fields from all tables of a MySQL database and a given string, possibly using syntax as

SELECT * FROM * WHERE * LIKE '%add_search_word%'

For that type of functionality provide “Search in all fields from every table of a MySQL database“.

<?php  
  // every table MySQL Search fields from MySQL database
  // set header	
  header("Content-Type: text/plain");  
  $host = "localhost";
  $username = "root";
  $password = "";
  $database = "itvc";  
  
  // connect sqli db
  $dbCon = mysqli_connect("localhost","root","","itvc");

function searchToAllDB($search)
{
    global $dbCon;
    $search_out = "";
    $sql_query = "show tables";
    $result = $dbCon->query($sql_query);
    if($result->num_rows > 0){
        while($row_val1 = $result->fetch_array()){
			$row_val = array();
            $table_name = $row_val1[0];
            $search_out .= $table_name." => ";
            $sql_search = "select * from ".$table_name." where ";
            $sql_search_fields_data = Array();
            $sql2 = "SHOW COLUMNS FROM ".$table_name;
            $row_val2 = $dbCon->query($sql2);
            if($row_val2->num_rows > 0){
                while($row_data2 = $row_val2->fetch_array()){
                    $colum_val = $row_data2[0];
                    $sql_search_fields_data[] = $colum_val." like('%".$search."%')";
                }
                $row_val2->close();
            }
            $sql_search .= implode(" OR ", $sql_search_fields_data);
			//print_r($sql_search_fields_data);
            $row_val3 = $dbCon->query($sql_search);
			$serch_rows = $row_val3->num_rows;
            $search_out .= $row_val3->num_rows."\n";
			echo "Table Name => ".$table_name."\n";
			echo "search count => ".$serch_rows."\n";
			echo "search row => ";
			if($search_out == 0)
			{
				echo "No result found";
			}
			while($row_val = mysqli_fetch_assoc($row_val3)) {
				echo "\n";	
				print_r($row_val);
			}
			echo "\n";
		 //print_r($row);
			
            if($row_val3->num_rows > 0){
                $row_val3->close();
            }
        }
        $result->close();
    }

    return $search_out;
}

// add your search word
$search_word = "Virtualization";
// result of search_word and 
// every table MySQL Search fields from MySQL database
print_r(searchToAllDB($search_word));
?>

You may also like submit form without page refresh using jQuery ajax – php

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  1  =  

We accept paid advance and paid guest Posting on our Site : Contact US