V
V
Vincent12017-01-12 12:47:40
PHP
Vincent1, 2017-01-12 12:47:40

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

4 answer(s)
F
FanatPHP, 2017-01-12
@FanatPHP

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 или Доктрину) - ничто по сравнению с возможностью **прочитать и понять**, для чего, вообще, данный код нужен, и как он это делает.
Поэтому излишняя автоматизация бывает очень вредна. И гоняться за ней не стоит.

I
ivkol, 2017-01-12
@ivkol

readbean

L
Lander, 2017-01-12
@usdglander Куратор тега PHP

Использовать QueryBuilder какой нить не вариант?

Артемий, 2017-01-12
@MetaAbstract

Вы можете использовать ORM (Doctrine или Propel)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question