pokemon-showdown-client/lib/ntbb-database.lib.php
Guangcong Luo 82e7a917ab Move session library inside repository
For too long, ntbb-session and ntbb-database have been maintained
outside of this repo, but no longer! All these files are now part of the
repository, making it significantly more self-contained.

If I had to say why it took this long, I think it was mostly inertia. It
was easier leaving them where they were than having to audit them for
private keys in the wrong places, etc.

I'm starting to think of PS more as sim first, website secondary than
the other way around, now. Especially now that we don't have a forum,
the website itself isn't really important... Maybe one day I'll get rid
of the landing page and make the sim itself the first thing you see when
you hit pokemonshowdown.com... but today is not that day!

The repo is still not "batteries-included" since I am not going to teach
anyone how to set up PHP and MySQL or even get the config files working.
But for anyone who wanted their own client, well, it gets a lot easier
to do now.
2016-10-20 13:16:06 -04:00

66 lines
1.4 KiB
PHP

<?php
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']);