-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TABLE IF NOT EXISTS urls ( | ||
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
name varchar(255) NOT NULL UNIQUE, | ||
created_at timestamp | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS url_checks ( | ||
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
url_id bigint REFERENCES urls (id), | ||
status_code int, | ||
h1 text, | ||
title text, | ||
description text, | ||
created_at timestamp | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
<?php | ||
|
||
namespace src; | ||
namespace Bosun\PhpProject9; | ||
|
||
class Database | ||
{ | ||
protected function __construct() | ||
protected \PDO $pdo; | ||
|
||
public function __construct() | ||
{ | ||
$databaseUrl = parse_url(getenv('DATABASE_URL')); | ||
$username = $databaseUrl['user']; | ||
$password = $databaseUrl['pass']; | ||
$host = $databaseUrl['host']; | ||
$port = $databaseUrl['port']; | ||
$dbName = ltrim($databaseUrl['path'], '/'); | ||
$dsn = "pgsql:host={$host};port={$port};dbname={$dbName};user={$username};password={$password}"; | ||
$this->pdo = new \PDO($dsn); | ||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | ||
} | ||
} |