I have little knowledge of PHP, so I can't judge the question itself, but generally, downvotes on a question that is not horrible in terms of grammar (i.e., it's not impossible to understand) have to do with doing your research. @slugster's answer points out different reasons which all stem from that same reason.
For example, here are some points (emphasis mine):
I was thinking that a static method might be the best answer but not having any familiarity with them ...
Well, your first step was then to learn static
methods and familiarize yourself with them.
... I am unsure if I would be actually creating lots of connections or reusing the same one.
Did you try running your code? Surely, there are ways to understand if you are reusing the connection simply by running your code. In this particular case, run the code in a loop and see if you get increased memory consumption, or print the $conn
reference you get back (note: I'm not a PHP programmer, so the term may be incorrect) to see if they are constant.
Have I got the right idea about static methods and will I be reusing the same connection or making new ones?
A quick search for PHP class static
led me to this page which says you cannot access non-static
variables from a static
function (which makes sense to me and is the same in C++ as well). This leads me to believe that you haven't tried the code at all.
It's OK to be a noob, but it's not OK to be lazy. While I know a great deal of C, I'm a noob in Haskell. Even then, before asking a question on Haskell, I may spend days trying to figure it out myself. In the end, when writing a question, I make sure every question I have had are tried out. Sometimes this leads to more research while writing the question and even leads to an answer.
In a widely used language like PHP, you can be sure any question you have as a noob is already answered somewhere. It may be hard to find, but it's there. If you have researched and experimented enough, your question could easily get to tens of paragraphs and include code, tables and figures.
Again, I don't know PHP much, but my best guess is that you haven't done your research and that's why you are getting downvotes. As a final note, searching Stack Overflow for [php] static db
quickly found me this question which seems to be your exact problem (also lacking static
for declaration of $conn
).
I'm going to close your question as a duplicate.