public function process($data) { $search = $_GET['q']; $siteId = $_GET['s']; if (isset($_GET['parent'])) { $parent = WDStringUtils::toUnixName($_GET['parent']); } else { $parent = null; } $title = isset($_GET['title']) && $_GET['title'] == 'yes'; if (!is_numeric($siteId) || $search == null || strlen($search) == 0) { return; } $search = pg_escape_string(preg_quote(str_replace(' ', '-', $search))); $siteId = pg_escape_string($siteId); $orTitle = $title ? "OR title ~* '^{$search}'" : ""; $query = "SELECT unix_name, COALESCE(title,unix_name) AS title FROM page "; $query .= "WHERE site_id ='{$siteId}' AND (unix_name ~* '^{$search}' {$orTitle})"; if ($parent) { $parent = pg_escape_string($parent); $query .= " AND parent_page_id IN (SELECT page_id FROM page WHERE unix_name = '{$parent}') "; } $query .= "ORDER BY unix_name"; Database::init(); return array('pages' => Database::connection()->query($query)->fetchAll()); }
function logAccess() { define('_VALID_CODE', true); include_once 'database.php'; $dbh = new Database(); $dbh->init(); $ipaddr_base = $_SERVER['REMOTE_ADDR']; if (is_array($ipaddr_base)) { $ipaddr = $ipaddr_base[0]; } else { $ipaddr = $ipaddr_base; } //echo("--> " . $ipaddr); $query = "SELECT * FROM downloads26 WHERE ipaddr = '{$ipaddr}';"; $result = $dbh->doQuery($query); if (mysql_num_rows(&$result) > 0) { /*$row = mysql_fetch_array(&$result); if (intval( $row['attempts'] ) > 50) { die("Sorry, you've attempted to download StealthBot too many times. Please contact Stealth by <a href='mailto:stealth@stealthbot.net'>email</a> if you need another copy, or if you received this message in error."); } */ $query = "UPDATE downloads26 SET attempts=attempts+1 WHERE ipaddr='{$ipaddr}';"; } else { $query = "INSERT INTO downloads26(ipaddr, attempts) VALUES('{$ipaddr}', 1);"; } mysql_free_result($result); $result = $dbh->doQuery($query); }
public function process($data) { // does not use data $search = $_GET['q']; if ($search == null || strlen($search) == 0) { return; } $search1 = pg_escape_string(preg_quote($search)); $search2 = pg_escape_string($search); Database::init(); $q1 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name ~* '^{$search1}' AND nick_name != '{$search2}'"; $q1 .= "ORDER BY nick_name LIMIT 20"; $q2 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name = '{$search2}' "; $db = Database::connection(); $result1 = $db->query($q1); $result1 = $result1->fetchAll(); $result2 = $db->query($q2); $result2 = $result2->fetchAll(); if ($result1 == null && $result2 != null) { $result = $result2; } if ($result2 == null && $result1 != null) { $result = $result1; } if ($result1 == null && $result2 == null) { $result = false; } // NOT null since it breakes autocomplete!!! if ($result1 != null && $result2 != null) { $result = array_merge($result2, $result1); } return array('users' => $result); }
/** * Returns the active database connection. */ public static function connection() { if (self::$connection == null) { Database::init(); } return self::$connection; }
function init($requestData) { if (CONFIG_API_LIVE) { if (!CONFIG_ENFORCE_SSL || isHTTPS()) { // if the client uses HTTPS (or it's not enforced) if (isset($_SERVER['HTTP_USER_AGENT'])) { // if User-Agent header is set if (preg_match('/Faceless-([a-z_-]+)-([0-9]+)/i', $_SERVER['HTTP_USER_AGENT'], $userAgent)) { // if User-Agent header has valid format $userAgentList = unserialize(CONFIG_API_CLIENTS); // if user agent uses valid platform and no outdated client software if (isset($userAgentList[$userAgent[1]]) && intval($userAgent[2]) >= $userAgentList[$userAgent[1]]) { // get the custom request timestamp from the HTTP headers $requestTimestamp = isset($_SERVER[CONFIG_HEADER_TIMESTAMP]) ? $_SERVER[CONFIG_HEADER_TIMESTAMP] : ''; // if the timestamp (verified by signature) is within the valid interval if (abs($requestTimestamp - time()) < 86400) { // get the signature provided by the client $signatureClient = isset($_SERVER[CONFIG_HEADER_SIGNATURE]) ? $_SERVER[CONFIG_HEADER_SIGNATURE] : ''; // generate the server signature for this request $signatureServer = base64_encode(hash_hmac(CONFIG_HMAC_ALGORITHM, getRequestIdentifier($requestData), CONFIG_API_SECRET, true)); // compare the server signature to the client signature for request verification if (hash_equals($signatureClient, $signatureServer)) { // integrity and authenticity of the request have been verified // initialize the database connection try { Database::init(CONFIG_DB_CONNECT_STRING, CONFIG_DB_USERNAME, CONFIG_DB_PASSWORD); } catch (Exception $e) { respond(array('status' => 'maintenance')); } // return with supplied user credentials return array('username' => isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '', 'password' => isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''); } else { respond(array('status' => 'bad_request')); } } else { respond(array('status' => 'bad_request')); } } else { respond(array('status' => 'outdated_client')); } } else { respond(array('status' => 'bad_request')); } } else { respond(array('status' => 'bad_request')); } } else { respond(array('status' => 'bad_request')); } } else { respond(array('status' => 'maintenance')); } return NULL; // suppress IDE warnings }
function __construct() { $this->titan = Loader::getInstance(); if (ENVIRONMENT != 'production') { $this->config = $this->titan->config('db', 'dev'); } else { $this->config = $this->titan->config('db'); } require_once SYSTEM_DIR . 'plugins/Database.php'; $this->db = Database::init($this->config); }
<?php require_once 'library/Database.php'; require_once 'library/User.php'; require_once 'library/Util.php'; require_once 'library/Post.php'; Database::init('sqlite:db/vanity.sqlite'); session_start();
public function mysql() { Database::init(); $book = Database::dispense('book'); $book->title = 'Hello'; $id = Database::store($book); Debug::show(R::findAll('book')); }
* Fourth, general purpose classes are loaded: the inflector and database classes. * Finally, the application object is created and initiated, handed over the control. * * @package phpscrabble */ session_start(); // autoload function __autoload($classname) { $dir = dirname(__FILE__) . '/lib'; if (file_exists($dir . '/class.' . $classname . '.php')) { require_once $dir . '/class.' . $classname . '.php'; } elseif (file_exists($dir . '/controller.' . $classname . '.php')) { require_once $dir . '/controller.' . $classname . '.php'; } elseif (file_exists($dir . '/model.' . $classname . '.php')) { require_once $dir . '/model.' . $classname . '.php'; } elseif (file_exists($dir . '/component.' . $classname . '.php')) { require_once $dir . '/component.' . $classname . '.php'; } elseif (file_exists($dir . '/helper.' . $classname . '.php')) { require_once $dir . '/helper.' . $classname . '.php'; } } // configuration $config = array('database' => array('host' => 'localhost', 'user' => 'phpscrabble', 'pass' => 'K4v2eps', 'db' => 'phpscrabble'), 'url_pre' => 'http://kelley.vanevert.nl', 'wbase' => '/phpscrabble', 'base' => dirname(__FILE__), 'path' => array('controller' => 'pages', 'action' => 'view', 'params' => array('home')), 'page_info' => array('title' => 'Scrabble!'), 'security' => array('salt' => 'y9348ijghosidjobhgwuoeihuswe0h8wuj4ei23wkjewkd0hiis')); // general purpose objects $Inflector = new Inflector(); $Database = new Database(); $Database->init(); // application object $App = new App(); $App->init();
/** * Database Plugin Loader * @return object */ public function database() { require_once SYSTEM_DIR . 'plugins/Database.php'; if (ENVIRONMENT != 'production') { return Database::init($this->config('db', 'dev')); } else { return Database::init($this->config('db')); } }
/** * {@inheritdoc } * Also creates the dsn string. */ public function init($host, $user, $pass, $db) { parent::init($host, $user, $pass, $db); $this->dsn = 'mysql:dbname=' . $this->db . ';host=' . $this->host; }
* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see {http://www.gnu.org/licenses/}. */ require_once __DIR__ . '/../../base.php'; // initialize the database connection try { Database::init(CONFIG_DB_CONNECT_STRING, CONFIG_DB_USERNAME, CONFIG_DB_PASSWORD); } catch (Exception $e) { throw new Exception('Could not connect to database'); } $daysUntilDestruction = intval(CONFIG_MESSAGES_SELF_DESTRUCT_TIMEOUT); if ($daysUntilDestruction < 1) { $daysUntilDestruction = 1; } // define a timeout and delete all content that has been created before that timestamp $timeout = time() - 3600 * 24 * $daysUntilDestruction; // delete old messages Database::delete("DELETE FROM messages WHERE time_active < " . intval($timeout)); // delete old comments Database::delete("DELETE FROM comments WHERE time_inserted < " . intval($timeout));
<?php header("Content-Type: text/plain"); $fnc = $_GET['fnc']; $file = $_GET['file']; if ($fnc != '' && $file != '') { require_once dirname(__FILE__) . '/database.php'; require_once dirname(__FILE__) . '/config.php'; Database::init(Config::$db); $src = Database::getSrc($fnc, $file); if (!empty($src)) { $src = highlight_string("<?php\n" . $src . "\n?>", true); $src = substr($src, 86, -70); echo $src; } else { echo "false"; } } else { echo "false"; }
/** * Get total time wasted by the player. * This is the main method used to return the json. Caching is done in in the main script. * * @param int $console The console number (1 for xbox, 2 for playstation) * @param string $name The player's username * @return string The json array for the complete response */ function get_time_wasted($console, $name) { try { $timer = new Timer(); $database = Database::init(DBHOST, DBNAME, DBUSER, DBPASS); $response = array(); $account = new DestinyAccount($name, $console); $account->lookup(); $account->get_accounts(); $response["displayName"] = $account->display_name; if (array_key_exists(1, $account->accounts)) { // If the account contains an entry for Xbox $account->fetch(1); $xbl_time = $account->accounts[1]; $response["xbox"] = $xbl_time; // Insert the time in the Xbox leaderboard $query = "REPLACE INTO leaderboard (`id`, `console`, `username`, `seconds`) VALUES (?, ?, ?, ?);"; $request = new Database($database, $query, array($xbl_time['membershipId'], 0, $xbl_time['displayName'], $xbl_time['timePlayed'])); $request->send(); // Get back the player's position $query = "SELECT @rownum:=@rownum+1 `rank`, `id` FROM leaderboard, (SELECT @rownum:=0) r ORDER BY `seconds` DESC;"; $request = new Database($database, $query, null); $request->receive(); $row = 0; foreach ($request->get_result() as $result) { if ($result['id'] == $xbl_time['membershipId']) { $row = $result['rank']; break; } } $response["xbox"]["leaderboardPosition"] = $row; } if (array_key_exists(2, $account->accounts)) { // If the account contains an entry for Playstation $account->fetch(2); $psn_time = $account->accounts[2]; $response["playstation"] = $psn_time; // Insert the time in the Playstation leaderboard $query = "INSERT IGNORE INTO leaderboard (`id`, `console`, `username`, `seconds`) VALUES (?, ?, ?, ?);"; $request = new Database($database, $query, array($psn_time['membershipId'], 1, $psn_time['displayName'], $psn_time['timePlayed'])); $request->send(); // Get back the player's position $query = "SELECT @rownum:=@rownum+1 `rank`, `id` FROM leaderboard, (SELECT @rownum:=0) r ORDER BY `seconds` DESC;"; $request = new Database($database, $query, null); $request->receive(); $row = 0; foreach ($request->get_result() as $result) { if ($result['id'] == $psn_time['membershipId']) { $row = $result['rank']; break; } } $response["playstation"]["leaderboardPosition"] = $row; } $response["totalTimePlayed"] = $account->total_time; $response["totalTimeWasted"] = $account->wasted_time; $account->error['LoadTime'] = $timer->get_timer(); $account->error['CacheTime'] = date("r"); return json_encode(array("Response" => $response, "Info" => $account->error)); } catch (Exception $e) { return json_encode(array("Response" => "", "Info" => $account->error)); } }
public function run() { Database::init(); $kc = new KarmaCalculator(); $kc->updateAll(); }
/** * While not generally useful all across the board, this little method * reduces a lot of code overhead in the data-handling classes and I just * don't feel like making a whole new class just for five lines of code. */ protected function getDb() { $db = Database::init(); return $db; }
<pre> <?php require_once '../vanity/library/Database.php'; Database::init('sqlite:../vanity/db/vanity.sqlite'); $db = Database::getInstance(); $sql = "SELECT *\n\t\tFROM users\n\t\tWHERE email = ?\n\t\tOR email = ?"; $params = array('*****@*****.**', '*****@*****.**'); $results = $db->query($sql, $params); var_dump($results); $results = $db->queryOne($sql, '*****@*****.**'); var_dump($results); $results = $db->queryCell($sql, '*****@*****.**'); var_dump($results); ?> </pre>
/** Full initialization - preload settings, locales, cache and database * @return void */ public static function full() { self::basic(); Cache::init(); Database::init(); }
* GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @category Wikidot * @package Wikidot_Tools * @version $Id$ * @copyright Copyright (c) 2008, Wikidot Inc. (http://www.wikidot-inc.com) * @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License */ chdir(dirname(__FILE__)); // unifies CLI/CGI cwd handling require '../php/setup.php'; // connect to the database Database::init(); $db = Database::connection(); $db->begin(); $files = $argv; array_shift($files); while (count($files)) { $dump = file_get_contents('../' . $files[0]); $query_no = 0; foreach (explode(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;', $dump) as $query) { try { $query_no++; if (trim($query) != "") { $db->query($query); } } catch (OzoneDatabaseException $e) { die("\n\nError occured at query number " . $query_no . ', file ' . $files[0] . ":\n" . htmlspecialchars($query) . "\n");
public function __construct() { $this->_db = Database::init(); }