note 40181 added to language.variables
| From: | ed dot xmg at rn2 dot php dot net | Date: | Tue, 24 Feb 2004 14:55:44 +0000 |
| Subject: | note 40181 added to language.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65650@lists.php.net to get a copy of this message | ||
Imagine you have a database which is crowded with tables, you'll need prefixes for the
table-names to make them easier to maintain.
But you also want an easy access with PHP.
<?php
$tablePrefix = 'music_'; // db table prefix
$tableVarPrefix = 'tbl'; // variable table prefix
$tables = Array( // table BASE names
'introtexts',
'languages',
'projects',
'project_categories',
'ratings',
'reviewer',
'reviews',
'tracks'
);
// Generation of global vars:
foreach($tables as $t) {
$varName = $tabelVarPrefix.strtoupper($t{0}).substr($t,1,strlen($t));
$$varName = $tablePrefix.$t;
} ?>
So you have all tables well defined as:
music_introtexts, music_languages, ...
These strings are stored like this:
$tblIntrotexts = 'music_introtexts';
$tblLanguages = 'music_languages';
This can safe some time if you do a lot with databases...
----
Manual Page -- http://www.php.net/manual/en/language.variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40181
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40181&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40181&report=yes
Search -- http://master.php.net/manage/user-notes.php