예제 #1
0
/**
 * @return DbSimple_MySQL
 */
function &amDb()
{
    static $v;
    if (!$v) {
        $am_db =& connectMysql($GLOBALS['config']['db']['mysql']);
        $v = array(0 => &$am_db);
    }
    return $v[0];
}
예제 #2
0
<?php

require 'local/config.inc.php';
require 'common.inc.php';
require 'mysql.inc.php';
session_start();
if (!isset($_SESSION['player_id'])) {
    die('Connect to a session first');
}
connectMysql('dyn');
$player_id = $_SESSION['player_id'];
$res = $DB->query("SELECT * FROM players WHERE id = " . $player_id);
if ($rs = $res->fetch()) {
    $_SESSION['session_id'] = $rs['session_id'];
} else {
    unset($_SESSION['session_id']);
    unset($_SESSION['player_id']);
    session_write_close();
    die('Unknown player ID');
}
$session_id = $_SESSION['session_id'];
$res = $DB->query("SELECT * FROM sessions WHERE id = " . $session_id);
if ($rs = $res->fetch()) {
    $player_host = $rs['player_host'];
    $status = $rs['status'];
    $nbquestions = $rs['nbquestions'];
    $public = $rs['public'];
} else {
    unset($_SESSION['session_id']);
    session_write_close();
    die('Unknown session ID');
예제 #3
0
파일: base.php 프로젝트: lvchenbaby/convey
<?php

$config = (include "config.php");
include "functions.php";
include "mysql.php";
define("CSS", "/view/css");
define("JS", "/view/js");
define("IMAGE", "/view/image");
include ROOT . "/controllers/Controller.php";
$dbconf = $config['dbconfig'];
$dbcon = connectMysql($dbconf);
$route = getRoute();
ob_start();
execAction($route);
$output = ob_flush();
예제 #4
0
<?php

require 'local/config.inc.php';
require 'common.inc.php';
require 'mysql.inc.php';
connectMysql();
$file = '';
if ($_GET['sound'] == 'newplayer') {
    $res = $DB->query("SELECT * FROM ressnd WHERE grp = 'Credits' AND name = 'NewPlayers'");
    $rs = $res->fetch();
    $vals = explode(',', $rs['val']);
    $num = intval($_GET['num']);
    $file = '../res-full/' . $rs['resfolder'] . '/' . $vals[$num % sizeof($vals)] . '.' . strtr(substr($_GET['type'], 0, 3), './', '--');
}
if ($file && file_exists($file)) {
    sendFile($file);
}
header('HTTP/1.0 404 Not Found');
예제 #5
0
파일: index.php 프로젝트: Mwyann/ydkjs
function postaction()
{
    global $DB, $session_id, $player_id, $players_ids;
    $data = $_POST['data'];
    if ($players_ids != '') {
        if (strpos($players_ids, '#' . $player_id . '#') === false) {
            // Si on ne fait pas partie des "joueurs" (donc on est un spectateur), alors on ne participe pas activement à l'action.
            echo json_encode(array('id' => -1));
            die;
        }
    }
    // TODO Vérifier l'action (à développer dans un second temps)
    if ($data['action'] == 'sync') {
        // Gérer l'action 'sync'
        $socket = getSocket();
        stream_set_timeout($socket, 10);
        // Timeout de 10 secondes.
        $nbconnections = substr_count($players_ids, '#') - 1;
        fwrite($socket, $player_id . ',' . $nbconnections . "\n");
        // n > 1 = On débloque tout le monde dès que n connexions ont envoyé un nombre > 1
        if (fread($socket, 1) == $nbconnections) {
            // On est le dernier : on ajoute l'action en base
            connectMysql('dyn');
            $DB->query("INSERT INTO actions (session_id, player_id, dateaction, actiondata) VALUES (" . $session_id . ", " . $player_id . ", NOW(), '" . addslashes(json_encode($data)) . "')");
        }
        fwrite($socket, '1');
        // On valide l'action
        @fclose($socket);
        echo json_encode(array('id' => 0));
        die;
    }
    // Ajouter l'action en base
    connectMysql('dyn');
    $DB->query("INSERT INTO actions (session_id, player_id, dateaction, actiondata) VALUES (" . $session_id . ", " . $player_id . ", NOW(), '" . addslashes(json_encode($data)) . "')");
    $action_id = $DB->lastInsertId();
    // "Réveiller" les autres joueurs pour leur indiquer qu'il y a une nouvelle action à lire
    $socket = getSocket();
    stream_set_timeout($socket, 10);
    // Timeout de 10 secondes.
    fwrite($socket, $player_id . ",1\n");
    // 1 = On débloque tout le monde immédiatement !
    @fclose($socket);
    echo json_encode(array('id' => $action_id));
}
예제 #6
0
파일: table.php 프로젝트: ajiyoshi/nekorm
        $schema = NekoSchema::getInstance("done_url", "id", array("user_id", "url", "created_on", "updated_on"));
        $schema->addOnInsertTimestamp("created_on");
        $schema->addOnInsertTimestamp("updated_on");
        $schema->addOnUpdateTimestamp("updated_on");
        parent::__construct($dbh, $schema);
    }
}
$t = new lime_test();
if ($dbh = connectSqlite()) {
    testInstance($t, $dbh);
    testInsertAndSelectAndDelete($t, $dbh);
    testUnique($t, $dbh);
    testNotFound($t, $dbh);
    testInsertAndUpdate($t, $dbh);
}
if ($dbh = connectMysql()) {
    testInstance($t, $dbh);
    testInsertAndSelectAndDelete($t, $dbh);
    testUnique($t, $dbh);
    testNotFound($t, $dbh);
    testInsertAndUpdate($t, $dbh);
}
function connectSqlite()
{
    try {
        $dbh = new PDO('sqlite::memory:');
        $dbh->query("\n\t\t\tcreate table done_url (\n\t\t\t\tid integer primary key,\n\t\t\t\tuser_id integer unique,\n\t\t\t\turl varchar(255) not null,\n\t\t\t\tcreated_on datetime not null,\n\t\t\t\tupdated_on datetime not null\n\t\t\t)\n\t\t\t");
        return $dbh;
    } catch (Exception $e) {
        return null;
    }
예제 #7
0
                 <td  class='text-header' width='100'>Time(s)</td>
                 <td  class='text-header' width='100'>Status</td>
             </tr>
             <?php 
 if (count($config) > 0) {
     ?>
                 <?php 
     $j = 0;
     foreach ($config as $key => $value) {
         $j++;
         $result = '';
         # Check
         $start_time = slog_time();
         switch ($value['type']) {
             case 'database':
                 $result = connectMysql($value['config']);
                 break;
             case 'api_curl_get':
                 $result = curlTruemoveHStandardGet($value['config']);
                 break;
             case 'redis':
                 $result = connectRedis($value['config']);
                 break;
             case 'test_wsdl':
                 $result = getWsdl($value['config']);
                 break;
         }
         $time = elog_time($start_time);
         if ($result != 'success') {
             $error[] = $result;
         }
예제 #8
0
 function guess_db_settings()
 {
     if (!$this->guess_table_pattern || !$this->guess_fields_pattern) {
         return array();
     }
     if ($this->config['user'] == '' || $this->config['host'] == '' || isset($this->config['other_db']) && !$this->config['other_db']) {
         $config = amConfig('db.mysql');
     } else {
         $config = $this->config;
         /// lets get name of first available database just for DbSimple
         /// because it does not work without database name
         $c = @mysql_connect($config['host'], $config['user'], $config['pass']);
         if (!$c) {
             return false;
         }
         $q = mysql_query("SHOW DATABASES", $c);
         list($db) = mysql_fetch_row($q);
         if ($db == '') {
             return false;
         }
         $config['db'] = $db;
     }
     $c = connectMysql($config);
     if ($c->error) {
         return false;
     }
     $c->setErrorHandler(null);
     $res = array();
     foreach ($dbs = $c->selectCol("SHOW DATABASES") as $dbname) {
         $tables = $c->selectCol("SHOW TABLES FROM {$dbname} LIKE '%{$this->guess_table_pattern}'");
         if (is_array($tables)) {
             foreach ($tables as $t) {
                 // check fields here
                 $info = $c->select("SHOW COLUMNS FROM {$dbname}.{$t}");
                 $infostr = "";
                 if (is_array($info)) {
                     foreach ($info as $k => $v) {
                         $infostr .= join(';', $v) . "\n";
                     }
                 }
                 $wrong = 0;
                 foreach ($this->guess_fields_pattern as $pat) {
                     if (!preg_match('|^' . $pat . '|m', $infostr)) {
                         $wrong++;
                     }
                 }
                 if ($wrong) {
                     continue;
                 }
                 $res[] = $dbname . '.' . substr($t, 0, -strlen($this->guess_table_pattern));
             }
         }
     }
     return $res;
 }