public function delink($user, $network) { db::init()->query("users.delink", array("user" => $user, "network" => $network)); $q = db::init()->query("users.linked", array("user" => $user)); $data = $q->fetch(PDO::FETCH_NUM); return $data[0]; }
public function __construct() { if (!session_id()) { session_start(); } $this->connect = db::init(); }
/** * initialise the database class */ function init_db($name = null) { require_once LIBRARY_DIR . "db.php"; if (!$name) { $name = DB::DEFAULT_CONNECT_NAME; } db::init($name); }
static function find($user, $hash = false) { $name = $hash ? "users.hashfind" : "users.find"; $q = db::init()->query($name, array("name" => $user)); if ($q->rowCount()) { $data = $q->fetch(PDO::FETCH_NUM); return $data[0]; } return false; }
function listPatterns($id) { $q = db::init()->query("pattern.getAll", array("id" => $id)); if ($q->rowCount()) { while ($row = $q->fetch(PDO::FETCH_ASSOC)) { $id = $row['patternID']; echo "<tr><td>" . $row['pattern'] . "</td><td><img src='images/arrow.gif'/></td><td>" . $row['output'] . "</td>"; echo "<td><a href='nm-manage-set.php?action=remove&s={$id}'><img src='images/cross.png' /></a></td>"; } } else { echo "<tr><td colspan='4'><span>No Patterns</span></td></tr>"; } }
function listAllHistory($id) { $q = db::init()->query("epoch.getall", array("id" => $id)); if ($q->rowCount()) { while ($row = $q->fetch(PDO::FETCH_ASSOC)) { echo "<tr><td>" . $row['iterations'] . "</td>"; echo "<td>" . $row['startMSE'] . "</td>"; echo "<td>" . $row['endMSE'] . "</td>"; echo "<td>" . date("j/m/Y g:i:s a", strtotime($row['epochDate'])) . "</td>"; echo "<td>" . $row['execTime'] . "</td>"; echo "<td>" . ($row['trainsetID'] == null ? "n" : "y") . "</td></tr>"; } } else { echo "<tr><td colspan='6'><span>No History</span></td></tr>"; } }
<?php /** * Exports training set * @author Louis Stowasser */ require "lib/controller.class.php"; $app = new Controller(); set_time_limit(300); if (!$_POST['file']) { die("No Post Data!"); } $app->display("header"); $q = db::init()->query("pattern.getAll", array("id" => $_POST['id'])); file_put_contents("lib/cache/" . $_POST['file'] . ".nms", ""); //clear file while ($row = $q->fetch(PDO::FETCH_ASSOC)) { //Append data to file file_put_contents("lib/cache/" . $_POST['file'] . ".nms", $row['pattern'] . ":" . $row['output'] . "\n", FILE_APPEND); } $app->assign("file", $_POST['file']); $app->display("export"); $app->display("footer");
bigtitle(); /*If account creation is closed, do not show the page!*/ if ($account_creation_closed) { die("Server Is Currently Closed To New Players"); } ## ## ## New Registration Process ## ## $facebook = new facebook(array('appId' => FB_ID, 'secret' => FB_SECRET)); $request = $facebook->getSignedRequest(); if ($request) { $register = $request['registration']; try { $db = db::init(); $fbId = isset($request['user_id']) ? $request['user_id'] : 0; $user = new user(); if ($fbId != 0) { if ($user->fbLogin($fbId)) { /*They have account, throw them back to the main page*/ header('Location: index.php'); exit; } } $sth = $db->prepare("SELECT * FROM " . $db_prefix . "account WHERE username = ?"); $sth->execute(array($register['username'])); if (!$sth->fetch()) { $sth = $db->prepare("SELECT * FROM " . $db_prefix . "account WHERE email = ?"); $sth->execute(array($register['email'])); if (false != $sth->fetch() && $fbId != 0) {
/** * Quickly caches one pattern and output from the nmesh cache * @param $id Network ID * @param $input Input string * @param $data Output array */ function quickCache($id, $input, $data) { db::init()->query("cache.save", array("id" => $id . implode("|", trim($input)), "network" => $id, "data" => implode("|", $data))); }
public static function initDb() { $db = db::init(); $db->initDb('initdata/tables.sql'); unset($db); }
<?php /** * Import training set * @author Louis Stowasser */ require "lib/controller.class.php"; $app = new Controller(); $data = $app->model->val->add($_POST, $_FILES); $app->model->val->run("import", $data); $content = file_get_contents($_FILES['file']['tmp_name']); $data = explode("\n", $content); foreach ($data as $line) { $input = substr($line, 0, strpos($line, ":")); $output = substr($line, strpos($line, ":") + 1, strlen($line)); if (validation::is_binary($input) && validation::is_binary($output)) { db::init()->query("pattern.add", array("id" => $_POST['id'], "pattern" => $input, "output" => $output)); } } Model::direct();
class db { public static $connection = NULL; private static $host = MYSQL_HOST; private static $username = MYSQL_USER; private static $passwd = MYSQL_PASS; private static $db = MYSQL_DBNAME; public static function init() { if(!self::$connection) { self::$connection = new mysqli(self::$host, self::$username, self::$passwd, self::$db); } } public static function escape($string) { return self::$connection->real_escape_string($string); } public static function ping() { if(!self::$connection->ping()) { self::$connection->close(); self::$connection = NULL; self::init(); } } } db::init(); ?>
if (strpos($_SERVER['SCRIPT_NAME'], 'install') !== false) { db::init($dbhost, $dbuser, $dbpass, null); } else { include_once APP_DIR . '/sessions.php'; global $mode; if ($mode != 'single') { $info = $subdomain = Auth::getClientSite(); if ($subdomain == 'auth') { $dbname = 'prosper_master'; db::init($dbhost, $dbuser, $dbpass, $dbname); } else { if (isset($_SERVER['subdomain'])) { $subdomain = $_SERVER['subdomain']; } $name = $subdomain == $reservedSubDomain ? 'prosper_master' : "prosper_{$subdomain}"; db::init($dbhost, $dbuser, $dbpass, $name); } } else { if ($dbname == '<insert db host here>') { die('Please configure the system config file'); } } $dbname = "`{$dbname}`"; $config = new Config(0); } //try to connect to memcache server if (ini_get('memcache.default_port')) { $memcacheInstalled = true; $memcache = new Memcache(); if (@$memcache->connect($mchost, 11211)) { $memcacheWorking = true;
<?php require "lib/controller.class.php"; $app = new Controller(); switch ($_GET['action']) { case "remove": Model::loadProxy("train")->validate($_GET['s']); db::init()->query("pattern.remove", array("id" => $_GET['s'])); break; case "add": $app->model->val->run("trainingset", $_POST); db::init()->query("pattern.add", array("pattern" => $_POST['input'], "id" => $_POST['id'], "output" => $_POST['output'])); break; case "rename": $app->model->val->run("setrename", $_POST); db::init()->query("train.update", array("label" => $_POST['label'], "id" => $_POST['id'])); break; case "delete": Model::loadProxy("train")->validate($_GET['s']); db::init()->query("train.remove", array("id" => $_GET['s'])); break; case "new": $app->model->val->run("newset", $_POST); db::init()->query("train.add", array("id" => $_POST['n'], "label" => $_POST['label'])); break; } Model::direct($_SERVER['HTTP_REFERER']);
function buildTree($id, $nn) { $uuid = 0; $output = "<ul>"; $lcount = count($nn->layer); for ($l = 0; $l < $lcount; $l++) { $output .= "<li class='layer'><a href='javascript:void(0);' onclick=\"toggle('ul" . ($uuid + 1) . "',this);\">-</a> Layer " . ($l + 1); $ncount = count($nn->layer[$l]->neuron); for ($n = 0; $n < $ncount; $n++) { $uuid++; if ($n == 0) { $output .= "<ul id='ul{$uuid}'>"; } $output .= "<li class='neuron'><a href='javascript:void(0);' onclick=\"toggle('ul" . ($uuid + 1) . "',this);\">+</a> Neuron " . ($n + 1); $scount = count($nn->layer[$l]->neuron[$n]->synapse); for ($s = 0; $s < $scount; $s++) { $uuid++; if ($s == 0) { $output .= "<ul id='ul{$uuid}' style='display:none'>"; } $output .= "<li class='synapse'>Synapse " . ($s + 1) . "</li>"; if ($s == $scount - 1) { $output .= "</ul>"; } } $output .= "</li>"; if ($n == $ncount - 1) { $output .= "</ul>"; } } $output .= "</li>"; } $output .= "</ul>"; db::init()->query("cache.save", array("id" => $id . "tree", "network" => $id, "data" => $output)); return $output; }
public function __construct() { if (!self::$db) { self::$db = db::init(); } if (!self::$table_prefix) { self::$table_prefix = mPHP::$CFG['table_prefix']; } }
public function validate($id) { $q = db::init()->query("train.validate", array("id" => $id, "user" => $_SESSION['id'])); return !!$q->rowCount(); //convert to boolean }
return self::$obj[$name]; } } //对外使用的接口 class db { protected static $db_default; protected static $cfg; public static function init($cfg) { self::$cfg = $cfg; isset($cfg['default']) && (self::$db_default = $cfg['default']['type']); } public static function selectdb($name) { return dbfactory::create($name, self::$cfg[$name]); } public static function __callStatic($name, $args) { self::selectdb('default'); call_user_func_array(array(self::$db_default, $name), $args); } } $cfg = array('default' => array('type' => 'mysql', 'host' => '192.168.200.10', 'username' => 'root', 'password' => '123456'), 'db1' => array('type' => 'mysql', 'host' => '192.168.200.20', 'username' => 'root', 'password' => '123456'), 'db2' => array('type' => 'oracle', 'host' => '192.168.200.30', 'username' => 'root', 'password' => '123456')); db::init($cfg); db::query('select * from user'); db::query('select * from role'); db::query('select * from test'); db::selectdb('db1')->query('select * from user'); db::selectdb('db1')->query('select * from admin'); db::selectdb('db2')->query('select * from bank');
<?php /** * Created by JetBrains PhpStorm. * User: R2 * Date: 23.08.12 * Time: 21:21 * To change this template use File | Settings | File Templates. */ db::init('localhost', 'root', '', 'poll'); var_dump(db::getInstance()->selectRow('SELECT * FROM test WHERE id = ?', array("1"))); var_dump(db::getInstance()->selectAll('SELECT * FROM test WHERE name LIKE ?', array('foo%')));