How to search in multiple tables in yii2


(dobuyme) #1

I want to implement a search in yii2 that will go through the entire table in the database to give the result.How is that possible in yii2.Thanks in advance.


(Alexander Makarov) #2

Usually it’s done via either fulltext search index if it’s supported by database or via specialized engine such as ElasticSearch, Sphinx or SOLR.


(Joao) #3

The question is not clear. Can you be more specific? Would you like to search for values in a table column? Is it a text column? Give us more details so we can help you.


(dobuyme) #4

i have to implement a global search form which searches in all tables in my database and all columns in the table


(Joao) #5

You will have to deal with the database schema to get all the table names.
Then iterate each table to get columns names and build your query for each table using the like operator for each column found on the table.
I suggest you take a look at Gii model generator code to understand how it works and then adapt to your needs.

I don’t know why you’re doing this, but depending on the size of your tables and the number of records on them it might take a while to do the search.