mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-22 01:55:56 -05:00
A hack is required to keep Database::escape's API the same, but otherwise this API lends itself to having the internals swapped out surprisingly well.
61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?php
|
|
|
|
include_once dirname(__FILE__).'/../config/config.inc.php';
|
|
|
|
class PSDatabase {
|
|
var $db = null;
|
|
|
|
var $server = null;
|
|
var $username = null;
|
|
var $password = null;
|
|
var $database = null;
|
|
var $prefix = null;
|
|
var $charset = null;
|
|
|
|
function __construct($dbconfig) {
|
|
$this->server = $dbconfig['server'];
|
|
$this->username = $dbconfig['username'];
|
|
$this->password = $dbconfig['password'];
|
|
$this->database = $dbconfig['database'];
|
|
$this->prefix = $dbconfig['prefix'];
|
|
$this->charset = $dbconfig['charset'];
|
|
}
|
|
|
|
function connect() {
|
|
if (!$this->db) {
|
|
$this->db = new PDO(
|
|
"mysql:dbname={$this->database};host={$this->server}",
|
|
$this->username,
|
|
$this->password
|
|
);
|
|
}
|
|
}
|
|
function query($query) {
|
|
$this->connect();
|
|
return $this->db->query($query);
|
|
}
|
|
function fetch_assoc($resource) {
|
|
return $resource->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
function fetch($resource) {
|
|
return $resource->fetch();
|
|
}
|
|
function escape($data) {
|
|
$this->connect();
|
|
$data = $this->db->quote($data);
|
|
return substr($data, 1, -1);
|
|
}
|
|
function error() {
|
|
if ($this->db) {
|
|
return $this->db->errorInfo()[2];
|
|
}
|
|
}
|
|
function insert_id() {
|
|
if ($this->db) {
|
|
return $this->db->lastInsertId();
|
|
}
|
|
}
|
|
}
|
|
|
|
$psdb = new PSDatabase($psconfig);
|