PHP Code to Search a Keyword in Whole Database

Searching a keyword in a MySql table can be easily implemented, but it has always been a cumbersome task to search a keyword in the whole database.

Moreover it is has been observed as a common need for many web application, particularly for advanced search like functionality.
PHP Code to Search a Keyword in Whole Database

Search a Keyword in Whole Database in PHP

Taking it into consideration, PHP has introduced a new class, named as “searchEntireDB”.

Just include this file into your code to make the searching of some word or a number in the whole database.

Here is the code for class “searchEntireDB” saved as searchEntireDB.php.


And here is the example code, showing the use of the above class .

It is important to mention here, how you will see the results.

Here is a snapshot of the search results, that will help you to understand the output.


1 -> result = name of the array containing the matching results.If result array is missing, it indicates that no match found for given keyword.
2 -> users = name of the table containing the matched records
3, 4 -> identifier,name = columns of the users table, containing the matched values
5, 6 -> JohnC, John C. = the matched values

Also with his useful class, you can also find the empty and non empty tables in the searched database, resulted in form of emptyDBs and notEmpty array respectively.

Leave a Comment