I had the following PHP mySQL code:
$q = @mysql_query("SELECT * FROM tablename WHERE admin_id = '" . $admin_id . "'");
while ($arr = mysql_fetch_array($q)) {
$user_settings[$arr['setting']] = html_entity_decode($arr['value']);
}
In my database I have a table with settings. Each row has an admin ID, a setting name, and a setting value.
For example, a row could be:
id|adminid|setting|value <-column names
1|1|settingName1|5
The code above resulted in variables in this format:
$user_settings['settingName1']
which had the value of "5" from the database.
I'm trying to convert this to the PDO methods that are used by WHMCS. This is my first time working with PDO. I'm trying to get the variable names and values to match the old way so that less code changes are required
So far I came up with this:
foreach (Capsule::table('tablename')->where('admin_id', '=', $admin_id)->get() as $user_settings) {
echo "<pre>".print_r($user_settings, true)."</pre>";
}
That outputs:
stdClass Object
(
[id] => 16
[admin_id] => 1
[setting] => settingName1
[value] => 5
)
stdClass Object
(
[id] => 15
[admin_id] => 1
[setting] => anotherSetting
[value] => ON
)
stdClass Object
(
[id] => 14
[admin_id] => 1
[setting] => yetAnotherSetting
[value] => ON
)
I have no idea how to get these settings to match the old format.
For example, the three examples shown above should end up like this:
$user_settings['settingName1'] (value should be: 5)
$user_settings['anotherSetting'] (value should be: ON)
$user_settings['yetAnotherSetting'] (value should be: ON)
I would really appreciate some help as I learn how PDO works.