Webpage for Games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
923 B

<?php
class MySQLConnection {
private int $port;
private string $host;
private string $user;
private string $pass;
private string $dbName = "all_projects";
private mysqli $mysqli;
public function __construct() {
$config = parse_ini_file($_SERVER['DOCUMENT_ROOT'].'/../secrets/mysql.ini');
$this->host = $config['host'];
$this->port = parse_ini_file($_SERVER['DOCUMENT_ROOT'].'/../env_config.ini')['local_mysql_port'];
$this->user = $config['username'];
$this->pass = $config['password'];
$this->createConn();
}
private function createConn() {
$this->mysqli = new mysqli($this->host . ":" . $this->port, $this->user, $this->pass, $this->dbName);
}
public function query($sql) {
return $this->mysqli->query($sql);
}
public function changeDB($dbName) {
$this->dbName = $dbName;
$this->mysqli->select_db($dbName);
}
public function __destruct() {
$this->mysqli->close();
}
}