Add project files
This commit is contained in:
41
00_vortrags-files/src/Database.php
Normal file
41
00_vortrags-files/src/Database.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
class Database
|
||||
{
|
||||
private array $config;
|
||||
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function testConnection(): bool
|
||||
{
|
||||
try {
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;dbname=%s',
|
||||
$this->config['host'],
|
||||
$this->config['name']
|
||||
);
|
||||
|
||||
$options = [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||
\PDO::ATTR_TIMEOUT => 5,
|
||||
];
|
||||
|
||||
$pdo = new \PDO(
|
||||
$dsn,
|
||||
$this->config['user'],
|
||||
$this->config['pass'],
|
||||
$options
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (\PDOException $e) {
|
||||
// In einer realen Anwendung würde hier geloggt werden
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
00_vortrags-files/src/HelloWorld.php
Normal file
10
00_vortrags-files/src/HelloWorld.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
class HelloWorld
|
||||
{
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Hallo Welt! Die PHP-Anwendung läuft in Docker.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user