, (DRY) , , , (SoC, . SRP). , databaseDo ($ action), : (1) (2) .
: "! , ! !", . , , , , , .
, - , , . , , . databaseDo() , , , "do", . :
$context = 'production';
function databaseDo($action) {
$db_hostname = ($context == 'production') ? 'http://remotehost.com' : 'localhost';
$db_username = ($context == 'production') ? 'apache' : 'root';
$pass = ($context == 'production') ? 'productionpassword' : 'developmentpassword';
try {
$dbh = new PDO("mysql:host=$db_hostname;dbname=mysql", $db_username, $db_password);
echo 'Connected to database';
if($context == 'production') {
}
if($context == 'development') {
}
$dbh = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
, .
DRY , , Singleton ( ) . , - . , , Singleton.