pokemon-showdown-client/website/lib/ntbb-database.lib.php
Guangcong Luo 2105dc8e57 Add website to client repository
Closes #1567

The main reason I'm not simply merging Annika's PR is because this
way makes it clearer that I'm taking responsibility for all this
code, that it's mostly code I wrote, and also because it makes it
easier to ensure that none of the files have been changed.

(Not that I don't personally trust Annika, but I have something
resembling an obligation to users not to expose them to risks based
on personal trust.)
2020-07-27 19:37:04 -04:00

69 lines
1.5 KiB
PHP

<?php
//debug_print_backtrace();
//die();
include_once dirname(__FILE__).'/../config/config.inc.php';
class NTBBDatabase {
var $db = null;
var $server = null;
var $username = null;
var $password = null;
var $database = null;
var $prefix = null;
var $charset = null;
//var $queries = array();
function NTBBDatabase($server, $username, $password, $database, $prefix, $charset) {
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->prefix = $prefix;
$this->charset = $charset;
}
function connect() {
if (!$this->db) {
$this->db = mysqli_connect($this->server, $this->username, $this->password, $this->database);
if ($this->charset) {
mysqli_set_charset($this->db, $this->charset);
}
}
}
function query($query) {
$this->connect();
//$this->queries[] = $query;
return mysqli_query($this->db, $query);
}
function fetch_assoc($resource) {
return mysqli_fetch_assoc($resource);
}
function fetch($resource) {
return mysqli_fetch_assoc($resource);
}
function escape($data) {
$this->connect();
return mysqli_real_escape_string($this->db, $data);
}
function error() {
if ($this->db) {
return mysqli_error($this->db);
}
}
function insert_id() {
if ($this->db) {
return mysqli_insert_id($this->db);
}
}
}
$psdb = new NTBBDatabase($psconfig['server'],
$psconfig['username'],
$psconfig['password'],
$psconfig['database'],
$psconfig['prefix'],
$psconfig['charset']);