I have a configuration table in MySQL with a single row of values, and want to create a series of constants with the values in that row, with the attribute serving as the name of the constant.
It is becoming clear to me that the hoops I’m jumping through to do this are probably way too complicated. No doubt this is a common requirement and it seems to me that I’m probably overcomplicating the issue.
Can anyone suggest how to do this efficiently?
Here’s what I’ve been working with, and it’s not happening for me;
[code=php]// — read the field names from the config row
$result = mysql_query(“SELECT * FROM configuration”) or die(__LINE__.” SELECT Error: “.mysql_error());
$numf = @mysql_num_fields($result);
if(!$numf)$numf=0;
echo “$numf”;
// — read the values from the config row
$row = mysql_fetch_array($result);
// — cycle through each one creating a constant with the value
// — fv == field value
// — fn == field name
// We start the index at 1 because we don’t care about field 0 which is the id attribute
for($i=1;$i<$numf;$i++){
$fn = mysql_field_name($result,$i);
$fv = $row[$fn];
define($fn,$fv);
echo “<br /><b>$fn = $fv</b>”;
}