Good practices with big queries?

Asked

Viewed 146 times

-4

Are there good practices when it comes to SQL queries within php? Or is there an alternative to not "smudge" the code with a giant query in the middle? Edit: What I was looking for was just views, only I didn’t know what name to look for, the answer chosen.

  • Hey, Vinicius, what’s up? Just so you can understand the Downvotes: avoid questions of opinionated and personal character, always bring codes (or part of code) to better illustrate and exemplify the question and always research, here less by here, if there is no more your question and answer to it.

  • What I meant by giant query is a query with more than 10 lines for example in the middle of php code. I was seeing that good methods are methods with few lines and with division of responsibilities. I don’t know if there’s any way to improve the code when it comes to that. I tried researching it before but found nothing talking about, or maybe I searched for the wrong thing.

  • 2

    Considering the use of a ORM can solve your problem

  • 1

    Possible duplicate of How to deal with multiple queries?

1 answer

1


Try creating a view in the database and calling in the PHP code. This way you avoid having to call a long query and leave all the logic in the view. So what I researched here is possible.

  • 1

    https://sites.google.com/site/pawarnitesh/home/php/mysql_view_php Here’s an example for you to see. I don’t know if you’ve used view before.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.