1 | <?php |
||
13 | class DB extends \Prefab |
||
14 | { |
||
15 | /** |
||
16 | * Parse a http-style dsn and return parts as an array |
||
17 | * |
||
18 | * @param string $httpDSN http-style dsn, e.g mysql://root:[email protected]:3306/development_db |
||
19 | * @return array string of http dsn parameters, e.g. |
||
20 | * { |
||
21 | * ["driver"]=> string(5) "mysql" |
||
22 | * ["scheme"] => string(5) "mysql" |
||
23 | * ["host"]=> string(9) "127.0.0.1" |
||
24 | * ["port"]=> int(3306) |
||
25 | * ["user"]=> string(4) "root" |
||
26 | * ["pass"]=> string(4) "root" |
||
27 | * ["name"]=> string(14) "development_db" |
||
28 | * ["path"]=> string(14) "development_db" |
||
29 | * } |
||
30 | * @see http://php.net/parse_url |
||
31 | */ |
||
32 | public static function parseHttpDsn(string $httpDSN): array |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Return an f3 (pdo) dsn based on config params OR existing dsn param if set |
||
48 | * |
||
49 | * @param array $config e.g. |
||
50 | * { |
||
51 | * ["driver"]=> string(5) "mysql" |
||
52 | * ["host"]=> string(9) "127.0.0.1" |
||
53 | * ["port"]=> int(3306) |
||
54 | * ["name"]=> string(14) "development_db" |
||
55 | * } |
||
56 | * @return string $dsn e.g. mysql:host=127.0.0.1;port=3306;dbname=development_db |
||
57 | * @see http://php.net/manual/en/class.pdo.php |
||
58 | */ |
||
59 | public static function createDbDsn(array $config): string |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Return a new \DB\SQL object from the dsn parameters |
||
76 | * |
||
77 | * @param string $dsn e.g. mysql:host=127.0.0.1;port=3306;dbname=development_db |
||
78 | * @param string $user |
||
79 | * @param string $pass |
||
80 | * @param array $options options to PDO |
||
81 | * @link https://fatfreeframework.com/sql |
||
82 | * @see http://php.net/manual/en/class.pdo.php |
||
83 | */ |
||
84 | public static function &newDsnDb(string $dsn, string $user, string $pass, array $options = []): \DB\SQL |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Return a new \DB\SQL object from the given parameters |
||
98 | * |
||
99 | * @param string|array http dsn string or arary params params for connection |
||
100 | * Requires: |
||
101 | * { |
||
102 | * ["driver"]=> string(5) "mysql" |
||
103 | * ["host"]=> string(9) "127.0.0.1" |
||
104 | * ["port"]=> int(3306) |
||
105 | * ["user"]=> string(4) "root" |
||
106 | * ["pass"]=> string(4) "root" |
||
107 | * ["name"]=> string(14) "development_db" |
||
108 | * } |
||
109 | * OR |
||
110 | * PDO dsn and and username, password |
||
111 | * @link https://fatfreeframework.com/sql |
||
112 | * @see http://php.net/manual/en/class.pdo.php |
||
113 | */ |
||
114 | public static function &newDb($params): \DB\SQL |
||
128 | |||
129 | |||
130 | } |
||
131 |