@@ -11,16 +11,18 @@ protected function getConnection()
1111 {
1212 if ($ this ->conn === null ) {
1313 if (self ::$ pdo == null ) {
14- self ::$ pdo = new \PDO ($ GLOBALS ['db_dsn ' ], $ GLOBALS ['db_user ' ], $ GLOBALS ['db_passwd ' ]);
14+ $ conf = $ this ->getConnectionOptions ();
15+ $ dsn = 'mysql:host= ' . $ conf ['host ' ] . ';port= ' . $ conf ['port ' ] . ';dbname= ' . $ conf ['dbname ' ];
16+ self ::$ pdo = new \PDO ($ dsn , $ conf ['user ' ], $ conf ['passwd ' ]);
1517 }
1618
1719 self ::$ pdo ->query ('
1820 CREATE TABLE IF NOT EXISTS `book` (
19- `id` INT(11) NOT NULL,
21+ `id` INT(11) NOT NULL AUTO_INCREMENT ,
2022 `name` VARCHAR(255) NOT NULL,
21- `isbn` VARCHAR(255) NOT NULL,
22- `author` VARCHAR(255) NOT NULL,
23- `created` INT(11) NOT NULL,
23+ `isbn` VARCHAR(255) NULL,
24+ `author` VARCHAR(255) NULL,
25+ `created` INT(11) NULL,
2426 PRIMARY KEY (`id`)
2527 )
2628 ' );
@@ -39,9 +41,11 @@ protected function getDataSet()
3941 protected function getConnectionOptions ()
4042 {
4143 return [
42- 'dbname ' => $ GLOBALS ['db_dbname ' ],
43- 'user ' => $ GLOBALS ['db_user ' ],
44- 'passwd ' => $ GLOBALS ['db_passwd ' ],
44+ 'host ' => getenv ('DB_HOST ' ),
45+ 'port ' => (int )getenv ('DB_PORT ' ),
46+ 'dbname ' => getenv ('DB_DBNAME ' ),
47+ 'user ' => getenv ('DB_USER ' ),
48+ 'passwd ' => getenv ('DB_PASSWD ' ),
4549 ];
4650 }
4751}
0 commit comments