Skip to content

Commit

Permalink
created database
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosun18 committed Nov 14, 2023
1 parent af9df35 commit 0ba4334
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"guzzlehttp/guzzle": "^7.8",
"imangazaliev/didom": "^2.0",
"illuminate/support": "^10.31",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"ext-pdo": "*"
}
}
15 changes: 15 additions & 0 deletions database.sql
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
);
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Slim\Flash;
use Carbon\Carbon;
use Valitron\Validator;
use Src\Database;
use Bosun\PhpProject9\Database;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\TransferException;
use DiDom\Document;
Expand Down
15 changes: 13 additions & 2 deletions src/Database.php
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);
}
}

0 comments on commit 0ba4334

Please sign in to comment.