1: <?php declare(strict_types=1);
2:
3: namespace Salient\Db;
4:
5: use LogicException;
6:
7: /**
8: * Database connection drivers
9: */
10: final class DbDriver
11: {
12: /**
13: * IBM Db2
14: */
15: public const DB2 = 0;
16:
17: /**
18: * Microsoft SQL Server
19: */
20: public const MSSQL = 1;
21:
22: /**
23: * MySQL or MariaDB
24: */
25: public const MYSQL = 2;
26:
27: /**
28: * SQLite
29: */
30: public const SQLITE = 3;
31:
32: /**
33: * @var array<DbDriver::*,string>
34: */
35: private static $AdodbDriverMap = [
36: self::DB2 => 'db2',
37: self::MSSQL => 'mssqlnative',
38: self::MYSQL => 'mysqli',
39: self::SQLITE => 'sqlite3',
40: ];
41:
42: /**
43: * @internal
44: *
45: * @param DbDriver::* $driver
46: */
47: public static function toAdodbDriver(int $driver): string
48: {
49: if (($adodbDriver = self::$AdodbDriverMap[$driver] ?? null) === null) {
50: throw new LogicException(
51: sprintf('Argument #1 ($driver) is invalid: %d', $driver)
52: );
53: }
54:
55: return $adodbDriver;
56: }
57: }
58: