-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror-handling.php
More file actions
29 lines (24 loc) · 946 Bytes
/
error-handling.php
File metadata and controls
29 lines (24 loc) · 946 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
use Neuron\Database\DatabaseException;
use Neuron\Database\DatabaseManager;
use Neuron\Database\Drivers\MysqlDatabaseDriver;
use Neuron\Extensibility\ExtensionStore;
use Neuron\Extensibility\InstantiatorInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/** @var LoggerInterface $logger */
/** @var InstantiatorInterface $instantiator */
/** @var EventDispatcherInterface $eventDispatcher */
$extensions = new ExtensionStore($instantiator, $logger, $eventDispatcher);
$database = new DatabaseManager($logger, $extensions, $eventDispatcher);
$database->connect('_default_', MysqlDatabaseDriver::class, [
'database' => 'nonexistent_db', // Intentional wrong DB name
'host' => 'localhost',
'username' => 'user',
'password' => 'wrongpassword',
]);
try {
$database->execute('SELECT * FROM users');
} catch (DatabaseException $e) {
echo "Database error: " . $e->getMessage();
}