Here is a little example, we have this table where we store constants name and there values (values that have the possibility to be modified from the administration cpanel):
CREATE TABLE `global_constants` (
`name` varchar(255) NOT NULL default '',
`value` varchar(255) NOT NULL default ''
) TYPE=MyISAM;
--
-- Dumping data for table `vars`
--
INSERT INTO `vars` VALUES ('_G_var1', 'Hello');
INSERT INTO `vars` VALUES ('_G_var2', 'world');
And this is how the code should look like:
/* mysql connection */
$sql_txt = "SELECT \r\n";
$sql_txt.= " name, `value` \r\n";
$sql_txt.= "FROM `global_constants` \r\n";
$sql_rez = mysql_query($sql_txt) or die(mysql_error());
if(mysql_num_rows($sql_rez)) {
while( ($sc = mysql_fetch_assoc($sql_rez)) ) {
if (!defined($sc['name'])) define($sc['name'],$sc['value']);
else die("This constant {$sc['name']} has already been defined!");
} mysql_free_result($sql_rez);
echo _G_var1." "._G_var2."!";
} else mysql_free_result($sql_rez);
I love "Hello world!" tutorials ... 😃