Answer the question
In order to leave comments, you need to log in
Add generics to db queries from PHP?
You need to make queries to the database, which has ~ 20 fields, with different conditions (>, <, =) for different fields.
Now I have to get a list of parameters at the input of my function and use the conditions to build a "manual" query.
Is there any solution that will make it easier to build queries to mysql from php and that will add versatility or something ... ?
Answer the question
In order to leave comments, you need to log in
It should be understood that even with the use of the tools listed above, one cannot do without "manual" query assembly.
But the most important thing is that it is not necessary.
Even if we strain and pile some kind of query autobuilder on our application, then in the end we will get the following consequences:
- a lot of time spent on searching, adapting, and finishing the aforementioned autobuilder
- emotions like "like this #%;%:?U# Does $^# work at all??!" when in half a year you have to add some new field
- an apotheosis, when you need to add a condition that is not supported by the autobuilder, some kind of IF EXISTS
Поверьте, затраты на написание запроса вручную (неважно, через убогое mysql_query или Доктрину) - ничто по сравнению с возможностью **прочитать и понять**, для чего, вообще, данный код нужен, и как он это делает.
Поэтому излишняя автоматизация бывает очень вредна. И гоняться за ней не стоит.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question