-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathdatabase.php
More file actions
29 lines (22 loc) · 724 Bytes
/
database.php
File metadata and controls
29 lines (22 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
function get_db(): PDO|null {
$settings = require( __DIR__ . "/settings.php" );
if( $settings['storage_type'] === "session" ) {
return null;
}
$db = new PDO(
$settings["db"]["dsn"],
$settings["db"]["username"] ?? null,
$settings["db"]["password"] ?? null
);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $db;
}
function get_conversation_class( $db ): ConversationInterface {
$settings = require( __DIR__ . "/settings.php" );
$conversation_class = [
"session" => SessionConversation::class,
"sql" => SQLConversation::class,
];
return new $conversation_class[$settings['storage_type']]( $db );
}