/
SqliteAdapter.php
57 lines (46 loc) · 1.35 KB
/
SqliteAdapter.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Bow\Database\Connection\Adapter;
use Bow\Database\Connection\AbstractConnection;
use InvalidArgumentException;
use PDO;
class SqliteAdapter extends AbstractConnection
{
/**
* The connexion name
*
* @var string
*/
protected ?string $name = 'sqlite';
/**
* SqliteAdapter constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
$this->connection();
}
/**
* @inheritDoc
*/
public function connection(): void
{
if (!isset($this->config['driver'])) {
throw new InvalidArgumentException("Please select the right sqlite driver");
}
if (!isset($this->config['database'])) {
throw new InvalidArgumentException('The database is not defined');
}
// Build the PDO connection
$this->pdo = new PDO('sqlite:' . $this->config['database']);
// Set the PDO attributes that we want
$this->pdo->setAttribute(
PDO::ATTR_DEFAULT_FETCH_MODE,
isset($this->config['fetch']) ? $this->config['fetch'] : $this->fetch
);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
}
}