note 40181 deleted from language.variables by vincent
| From: | vincent@php.net | Date: | Tue, 24 Feb 2004 15:56:47 +0000 |
| Subject: | note 40181 deleted from language.variables by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65654@lists.php.net to get a copy of this message | ||
Note Submitter: e d . x m g [ta] a r j i h
----
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...