i am working on a new php application, i have stored classes and functions in separate files and included them in my application.
my question is about sql queries, should i include them as functions in my func.php file or is it ok to have the queries sitting in the code for my application?
my application is already including files for functions, classes, jquery, css etc. is there a limit to how many i should include? i have read a few of the application development articles on other sites, but none of them address the actual database queries.
looking for a “best practices” type of answer here, i am a little new to application development and am just looking for some guidance on setting up a web application
It’s perfectly fine to have the queries in your actual code. It’s better than code them in the function, because functions and classes are meant to be generic, meaning you can use them over and over for different projects. If you were to code the queries in the functions that generic property would be lost.
And I’m not aware of any limitation on the number of files you can include. The websites I build so far use somewhere between 20 and 90 server-side includes and they all work just fine.
Be sure to understand that stuff like jQuery are client-side includes and the PHP files are server-side includes.
As far as the number of client-side includes, again no limit, but more files = more http requests = slower website.
BTW. I used to have (before I started using Active Record) a Db class with a function select($what, $from, $where, $orderby, $groupby, $having, $offset, $limit)
I think you can guess the implementation. For me this made life much easier than constantly writing complete queries.
Also, you can do nice things with arrays and INSERT / UPDATE queries.