34 lines
No EOL
881 B
PHP
34 lines
No EOL
881 B
PHP
<?php
|
|
|
|
class Database {
|
|
private $mysqli = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$config = require("config.php");
|
|
$this->mysqli = new mysqli($config["db_host"], $config["db_user"], $config["db_pass"], $config["db_name"], $config["db_port"]);
|
|
if ($this->mysqli->connect_errno) {
|
|
die("Failed to connect to database: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error);
|
|
};
|
|
}
|
|
|
|
public function query($query="")
|
|
{
|
|
return $this->mysqli->query($query);
|
|
}
|
|
|
|
public function escape($string="")
|
|
{
|
|
return $this->mysqli->real_escape_string($string);
|
|
}
|
|
|
|
public static function execute_query($query="")
|
|
{
|
|
return (new self())->query($query);
|
|
}
|
|
|
|
public static function escape_string($string="")
|
|
{
|
|
return (new self())->escape($string);
|
|
}
|
|
} |