Hey guys,
here is the table structure:
Table name: globalsettings
column names: setting, value, description
An example query could be this:
$query = "SELECT * FROM globalsettings WHERE setting = 'name'";
Okay, so here is what I am trying to do (I am using PDO for DB activity, but just starting to learn PDO).
I have a class that will set sitewide global settings. What I am trying to do is set each propery in the class to the corresponding DB value. For example:
$config = new globalSettings;
echo $config->sitename;
When I echo $config->sitename, it should print out the website name that is stored in the DB.
Now, I do know how to do this, but the problem I have is that I only know how to do this by adding WHERE clause to the query -- "SELECT * FROM globalsettings WHERE setting = 'setting'";
which I want to avoid, because I have about 80 rows right now, and I dont want to make 80 different queries just to set each property.
My current code (stored in the class) looks like this:
`$sql = "SELECT * FROM globalsettings";
$q = $db->prepare($sql);
$q->execute();
foreach($q as $row)
{
$this->baseurl = $row['BASEURL'];
$this->subdir = $row['SUB_DIR'];
$this->cur_ver = $row['value'];
}`
but this doesn't look right.
How would I build a query so that it fetches all of the rows and data, and set the properties for me, all in one query?
As always, thank you so much!