2021-11-12 16:01:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* database.php
|
|
|
|
*
|
|
|
|
* Establishes a database connection using its credentials.
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace wishthis;
|
|
|
|
|
|
|
|
class Database
|
|
|
|
{
|
|
|
|
public \PDO $pdo;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
public string $host,
|
|
|
|
public string $database,
|
|
|
|
public string $user,
|
|
|
|
public string $password,
|
|
|
|
) {
|
|
|
|
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . ';port=3306;charset=utf8';
|
|
|
|
$options = array();
|
|
|
|
|
2022-01-14 13:13:07 +00:00
|
|
|
$this->pdo = new \PDO($dsn, $this->user, $this->password, $options);
|
2021-11-12 16:01:04 +00:00
|
|
|
}
|
2021-11-15 08:45:36 +00:00
|
|
|
|
2021-11-15 11:32:44 +00:00
|
|
|
public function query(string $query)
|
2021-11-15 08:45:36 +00:00
|
|
|
{
|
2021-11-15 11:32:44 +00:00
|
|
|
return $this->pdo->query(
|
|
|
|
$query,
|
|
|
|
\PDO::FETCH_ASSOC
|
|
|
|
);
|
2021-11-15 08:45:36 +00:00
|
|
|
}
|
2021-11-12 16:01:04 +00:00
|
|
|
}
|