Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
<?php
$GLOBALS['prefix'] = 'blub_';
function f()
{
echo $GLOBALS['prefix'];
}
f();
<?php
define('PREFIX', 'blub_');
function f()
{
echo PREFIX;
}
f();
<?php
// In einer Konfigurationsdatei (kann auch INI-Format haben oder so)
$config = array(
'prefix' => 'blub_'
);
// Config-Klasse
class Config
{
protected $data = array();
public function __construct(array $configData)
{
$this->data = $configData;
}
public function get($key)
{
if (!key_exists($key, $this->data)) {
throw new Exception('Config value for ' . $key . ' not set');
}
return $this->data[$key];
}
}
// Klasse, die auf Datenbank zugreift
class Db_Model
{
protected $tablePrefix;
function __construct($tablePrefix)
{
$this->tablePrefix = $tablePrefix;
}
public function getSomethingFromDatabase()
{
$q = "SELECT ... FROM `" . $this->tablePrefix . "data`";
echo $q;
}
}
// Test
$c = new Config($config);
$m = new Db_Model($c->get('prefix'));
$m->getSomethingFromDatabase();