I am trying to optimize a a PHP/MySQL site.
I need to know a couple of things. I want to hit the db as little as possible, so I am using arrays to store values. When I do my initial call to the db to get info, I do this:
http://www.mydomain.com/?id=12345
(This is how a user typically arrives at the site.)
I check the id against the db:
$my_array = mysql_fetch_row(mysql_query("select * from table_name where id = '$id'"));
Here is my question:
Is the db queried when I define the variable, or when I call the variable?
(ie: echo "$my_array[0]"; )
If it queries when I use the variable, does it query MySQL every time I use the variable or just the first time so I can use the values in the array without querying again?
I want to grab all the info on my member when they come in only one time. Then, I want to use that array multiple times without hitting the db each time I need the data.
Thanks