We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to search a whole database with Phalcon

Hi, everyone !

I'm a Phalcon newbie. I want to create a function that receives a string, or an integer... and then the function will search a whole database and return rows which are matched the given strings...Does anyone have any suggestion?

Thanks !

Why do you need so?

You could use in controllers DI helper:

public function indexAction() {
    $this->db->query("...");
}

And you can user any SQL syntax in there to achieve your goal.

edited Mar '15

Hi @Pavel ! Because I want to create a search bar for my website which will search the whole database. If I use

modelName::find(conditions)

I can only search one table and with specific columns. I would like to have a function like this

findAll(string $data, array $DontSearchThoseTables)



4.7k
Accepted
answer

If you have only a few tables you could do a query to search all especially if they can be joined or using UNION but you'd have to query all columns.

SELECT FROM table1 WHERE ... UNION SELECT FROM table2 WHERE ...;

A product like Elasticsearch or Sphinx is what this sort of problem is for.