public static function Instance($server, $database, $username, $password, $port = 5432) { if (!isset(EasyPDO::$Instance)) { $connectionString = 'pgsql:host=' . $server . ' port=' . $port . ' dbname=' . $database; EasyPDO::$Instance = new EasyPDO_Postgres($connectionString, $username, $password); } return EasyPDO::$Instance; }
public static function Instance($server, $database, $username, $password) { if (!isset(EasyPDO::$Instance)) { $connectionString = 'mysql:host=' . $server . ';dbname=' . $database; EasyPDO::$Instance = new EasyPDO_MySQL($connectionString, $username, $password); } return EasyPDO::$Instance; }
/** * @static * * @param $server * @param $database * @param $username * @param $password * * @return \EasyPDO */ public static function Instance($server, $database, $username, $password) { if (!\EasyPDO::$Instance) { $connectionString = 'mysql:host=' . $server . ';dbname=' . $database; \EasyPDO::$Instance = new Mysql($connectionString, $username, $password); // we want results back as ASSOC Array \EasyPDO::SetFetchMode(\EasyPDO::FETCH_MODE_ASSOCIATIVE_ARRAY); } return \EasyPDO::$Instance; }
public static function Instance($filename = null) { if (!isset(EasyPDO::$Instance)) { if (!$filename || !file_exists($filename) || is_dir($filename)) { $connectionString = 'sqlite::memory'; } else { $connectionString = 'sqlite:' . $filename; } EasyPDO::$Instance = new EasyPDO_SQLite($connectionString); } return EasyPDO::$Instance; }
<?php include_once 'class.db.php'; global $database; $database = new EasyPDO("mysql:host=127.0.0.1;port=8889;dbname=malandain;charset=UTF8", "root", "root"); $userQuery = "CREATE TABLE IF NOT EXISTS users (" . "ID INT NOT NULL AUTO_INCREMENT," . "username varchar(255) NOT NULL," . "password_hash TEXT NOT NULL," . "display_name VARCHAR(255) NOT NULL," . "email TEXT NOT NULL," . "PRIMARY KEY (ID)" . ");"; $eventsQuery = "CREATE TABLE IF NOT EXISTS events (" . "ID INT NOT NULL AUTO_INCREMENT," . "title varchar(255) NOT NULL," . "slug varchar(255) NOT NULL," . "location TEXT," . "PRIMARY KEY (ID)" . ");"; $potsQuery = "CREATE TABLE IF NOT EXISTS pots (" . "ID INT NOT NULL AUTO_INCREMENT," . "title varchar(255) NOT NULL," . "slug varchar(255) NOT NULL," . "amount DECIMAL(10,6) NOT NULL DEFAULT 0.0," . "num_people INT NOT NULL DEFAULT 0," . "status enum('open', 'closed', 'paid') NOT NULL DEFAULT 'open'," . "currency enum('euro', 'chf', 'dollar') NOT NULL DEFAULT 'chf'," . "event_id INT," . "PRIMARY KEY (ID)" . ");"; $spendingsQuery = "CREATE TABLE IF NOT EXISTS spendings (" . "ID INT NOT NULL AUTO_INCREMENT," . "amount DECIMAL(10,6) NOT NULL DEFAULT 0.0," . "description TEXT NOT NULL DEFAULT ''," . "date DATETIME," . "author INT," . "pot_id INT," . "PRIMARY KEY (ID)" . ");"; $potMembersQuery = "CREATE TABLE IF NOT EXISTS pot_members (" . "pot_id INT," . "user_id INT," . "weight DOUBLE NOT NULL DEFAULT 1.0," . "PRIMARY KEY (pot_id)" . ");"; $spendingsPeopleQuery = "CREATE TABLE IF NOT EXISTS spendings_people (" . "spending_id INT," . "user_id INT," . "PRIMARY KEY (spending_id)" . ");"; $database->run($userQuery); $database->run($eventsQuery); $database->run($potsQuery); $database->run($spendingsQuery); $database->run($potMembersQuery); $database->run($spendingsPeopleQuery);
public function FetchAll($sql) { $this->PrepareSQL($sql); $args = func_get_args(); array_shift($args); $this->BindParams($args); $this->Query->execute(); if (EasyPDO::$FetchMode == EasyPDO::FETCH_MODE_CLASS) { return $this->Query->fetchAll(EasyPDO::GetFetchMode(), EasyPDO::$FetchClass); } else { return $this->Query->fetchAll(EasyPDO::GetFetchMode()); } }
<?php //error_reporting(E_ALL); //ini_set('display_errors', 1); date_default_timezone_set("Asia/Hong_Kong"); require 'EasyPDO.php'; $post_json = json_decode($HTTP_RAW_POST_DATA, true); $easyPDO = new EasyPDO(); $public_white_list = array('fflog', 'nodelog', 'usercount'); if (in_array(getparam('api'), $public_white_list)) { call_user_func($post_json['api']); // for debug echo $HTTP_RAW_POST_DATA; } else { return_error_msg('No such api found:' + getparam('api')); //echo $HTTP_RAW_POST_DATA; } $easyPDO->closeDB(); exit; /* functions */ function getparam($key) { global $post_json; return isset($post_json[$key]) ? $post_json[$key] : ''; } function return_error_msg($msg) { echo json_encode(array('error' => $msg)); }