当前位置: 首页>>代码示例>>PHP>>正文


PHP DBAccess::QueryItem方法代码示例

本文整理汇总了PHP中DBAccess::QueryItem方法的典型用法代码示例。如果您正苦于以下问题:PHP DBAccess::QueryItem方法的具体用法?PHP DBAccess::QueryItem怎么用?PHP DBAccess::QueryItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBAccess的用法示例。


在下文中一共展示了DBAccess::QueryItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render_chat_messages

/**
 * Render the div full of chat messages.
 * @param $chatlength Essentially the limit on the number of messages.
**/
function render_chat_messages($chatlength, $show_elipsis = null)
{
    // Eventually there might be a reason to abstract out get_chats();
    $sql = new DBAccess();
    $sql->Query("SELECT sender_id, uname, message, age(now(), date) as ago FROM chat join players on chat.sender_id = player_id ORDER BY chat_id DESC LIMIT {$chatlength}");
    // Pull messages
    $chats = $sql->fetchAll();
    $message_rows = '';
    $messageCount = $sql->QueryItem("select count(*) from chat");
    if (!isset($show_elipsis) && $messageCount > $chatlength) {
        $show_elipsis = true;
    }
    $res = "<div class='chatMessages'>";
    $previous_date = null;
    $skip_interval = 3;
    // minutes
    foreach ($chats as $messageData) {
        $l_ago = time_ago($messageData['ago'], $previous_date);
        $message_rows .= "<li>&lt;<a href='player.php?player_id={$messageData['sender_id']}'\n\t\t     target='main'>{$messageData['uname']}</a>&gt; " . out($messageData['message']) . " <span class='chat-time'>{$l_ago}</span></li>";
        $previous_date = $messageData['ago'];
        // Store just prior date.
    }
    $res .= $message_rows;
    if ($show_elipsis) {
        // to indicate there are more chats available
        $res .= ".<br>.<br>.<br>";
    }
    $res .= "</div>";
    return $res;
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:34,代码来源:lib_chat.php

示例2: __construct

 public function __construct($player_id_or_username)
 {
     $sql = new DBAccess();
     if (!is_numeric($player_id_or_username)) {
         $sel = "select player_id from players where uname = '" . $player_id_or_username . "' limit 1";
         $this->player_id = $sql->QueryItem($sel);
     } else {
         $this->player_id = $player_id_or_username;
     }
     $dao = new PlayerDAO($sql);
     $this->vo = $dao->get($this->player_id);
 }
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:12,代码来源:Player.class.php

示例3: test_player_obj

function test_player_obj()
{
    // in: player_id, out: valid db save
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $player = new Player($player_id);
    assert($player->vo->player_id == $player_id);
    $orig_clan = $player->vo->clan_long_name;
    $player->vo->clan_long_name = 'Testingz';
    $player->save();
    $changed_player = new Player($player_id);
    $changed_clan = $changed_player->vo->clan_long_name;
    $changed_player->vo->clan_long_name = $orig_clan;
    assert($changed_clan == 'Testingz');
    // in: player uname, out: valid db save
    $player = new Player('glassbox');
    assert($player->vo->player_id == $player_id);
    $orig_clan = $player->vo->clan_long_name;
    $player->vo->clan_long_name = 'Testingz';
    $player->save();
    $changed_player = new Player($player_id);
    $changed_clan = $changed_player->vo->clan_long_name;
    $changed_player->vo->clan_long_name = $orig_clan;
    assert($changed_clan == 'Testingz');
    // in: player status check, out: no errors
    $player = new Player('glassbox');
    assert($player->vo->player_id == $player_id);
    $orig_clan = $player->vo->clan_long_name;
    $player->vo->clan_long_name = 'Testingz';
    $player->save();
    $changed_player = new Player($player_id);
    $changed_clan = $changed_player->vo->clan_long_name;
    $changed_player->vo->clan_long_name = $orig_clan;
    assert($changed_clan == 'Testingz');
    // in: player, out: vo of player data
    $player = new Player('glassbox');
    $vo = $player->as_vo();
    assert($vo instanceof PlayerVO);
    // in: player, out: array of player data
    $player = new Player('glassbox');
    $arr = $player->as_array();
    assert(count($arr) > 0);
    var_dump($arr);
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:45,代码来源:lib_char_tests.php

示例4: render_clan_join

function render_clan_join($process = null, $username, $clan_name)
{
    $sql = new DBAccess();
    if ($process == 1) {
        $confirm = $sql->QueryItem("SELECT confirm FROM players WHERE uname = '{$username}'");
        $url = message_url("clan_confirm.php?clan_joiner=" . rawurlencode($username) . "&confirm={$confirm}&clan_name=" . rawurlencode($clan_name), 'Confirm Request');
        $join_request_message = "CLAN JOIN REQUEST: {$username} has sent you a clan request.\n            If you wish to allow this ninja into your clan click the following link:\n            {$url}";
        send_message(get_user_id($username), get_user_id($clan_name), $join_request_message);
        echo "<div>***Your request to join this clan has been sent to {$clan_name}***</div>\n";
    } else {
        //Clan Join list of available Clans
        $clan_leaders = $sql->FetchAll("SELECT uname,level,clan,clan_long_name FROM players\n            WHERE lower(uname) = lower(clan) AND clan_long_name != '' AND confirmed = 1");
        echo "<p>Clans Available to Join</p>\n        <p>To send a clan request click on that clan leader's name.</p>\n        <ul>";
        foreach ($clan_leaders as $leader) {
            echo "<li><a href=\"clan.php?command=join&clan_name={$leader['clan']}&process=1\">\n                    Join {$leader['clan_long_name']}</a>.\n                    Its leader is <a href=\"player.php?player=" . rawurlencode($leader['uname']) . "\">\n                    {$leader['uname']}</a>, level {$leader['level']}.\n                    <a href=\"clan.php?command=view&clan_name={$leader['clan']}\">View This Clan</a>\n                </li>\n";
        }
        echo "</ul>";
    }
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:19,代码来源:lib_clan.php

示例5: get_user_id

function get_user_id($name = null)
{
    $sql = new DBAccess();
    if ($name === null) {
        $name = get_username();
    }
    return $sql->QueryItem("select player_id from players where uname = '" . sql($name) . "'");
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:8,代码来源:lib_auth.php

示例6: test_PlayerDAO

function test_PlayerDAO()
{
    // in: player_id, out: vo with uname and player_id.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    //var_dump($player_vo);
    assert(isset($player_vo));
    assert(isset($player_vo->uname));
    assert(isset($player_vo->player_id));
    // in: player_id, out: vo with same id.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2->player_id == $player_id);
    // in: player_id, out: vo with same username.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2->uname == 'glassbox');
    // in: player_id that doesn't exist, out: null
    $player_id = 999999;
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2 === null);
    // in: non-numeric player_id, out: false
    $player_id = 'not-a-player-id';
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2 === false);
    // in: player_vo, change the energy, save it. out: get that player, compare energy
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo_original = $dao->get($player_id);
    assert($player_vo_original->player_id == $player_id);
    $orig_energy = $player_vo_original->energy;
    $player_vo_original->energy = $player_vo_original->energy + 2;
    $dao->save($player_vo_original);
    $player_vo_after = $dao->get($player_vo_original->player_id);
    assert($orig_energy == $player_vo_after->energy - 2);
    // in: player_vo, change the energy, save it. out: get that player, compare energy
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo_original = $dao->get($player_id);
    $starting_clan = $player_vo_original->clan_long_name;
    $player_vo_original->clan_long_name = 'TestClanChange';
    $dao->save($player_vo_original);
    $changed_vo = $dao->get($player_vo_original->player_id);
    $changed_clan = $changed_vo->clan_long_name;
    $changed_vo->clan_long_name = $starting_clan;
    $dao->save($changed_vo);
    assert('TestClanChange' == $changed_clan);
    // in: a player_vo to change and save then delete, out: successful deletion
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    assert(isset($player_vo->player_id));
    $player_vo->player_id = null;
    $player_vo->uname = "TestUserName2";
    $player_vo->pname = "dummypassword";
    $dao->save($player_vo);
    $player_id_sel = "select player_id from players where uname = 'TestUserName2'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    assert(isset($player_vo->player_id));
    $deleted = $dao->delete($player_vo);
    // Need a player_id to delete.
    assert($deleted == true);
    $player_id_sel = "select player_id from players where uname = 'TestUserName2'";
    $deleted_id = $db->QueryItem($player_id_sel);
    assert($deleted_id == null);
    // in: a new player_vo to save n delete, out: no such new vo.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo1 = $dao->get($player_id);
    assert(isset($player_vo1->player_id));
    $player_vo1->player_id = null;
    $username = "TestUserName2" . rand();
    $player_vo1->uname = $username;
    $player_vo1->pname = "dummypassword";
    $dao->save($player_vo1);
//.........这里部分代码省略.........
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:101,代码来源:lib_db_tests.php

示例7: get_rank

function get_rank($username, $sql = null)
{
    if (!$sql) {
        $sql = new DBAccess();
    }
    $rank = $sql->QueryItem("SELECT rank_id FROM rankings WHERE uname = '" . $username . "'");
    $rank = $rank > 0 ? $rank : 1;
    // Make rank default to 1 if no valid ones are found.
    return $rank;
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:10,代码来源:lib_player.php

示例8: getStatus

function getStatus($who)
{
    global $sql, $status_array;
    if (!$sql) {
        $sql = new DBAccess();
    }
    $status = $sql->QueryItem("SELECT status FROM players WHERE uname = '{$who}'");
    if ($who == SESSION::get('username')) {
        $_SESSION['status'] = $status;
    }
    $status_array['Stealth'] = $status & STEALTH ? 1 : 0;
    $status_array['Poison'] = $status & POISON ? 1 : 0;
    $status_array['Frozen'] = $status & FROZEN ? 1 : 0;
    $status_array['ClassState'] = $status & CLASS_STATE ? 1 : 0;
    $status_array['Skill1'] = $status & SKILL_1 ? 1 : 0;
    $status_array['Skill2'] = $status & SKILL_2 ? 1 : 0;
    $status_array['Invited'] = $status & INVITED ? 1 : 0;
    return $status_array;
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:19,代码来源:commands.php

示例9: revive_players

/**
 * Revive up to a small max in minor hours, and a stable percent on major hours.
 * Defaults
 * sample_use: revive_players(array('just_testing'=>true));
 * @params array('full_max'=>80, 'minor_revive_to'=>100, 'major_revive_percent'=>5,
 *      'just_testing'=>false)
**/
function revive_players($params = array())
{
    // Previous min/max was 2-4% always, ~3000 players, so 60-120 each time.
    // In: full_max, default 80%
    $full_max = isset($params['full_max']) ? $params['full_max'] : 80;
    // minor_revive_to, default 100
    $minor_revive_to = isset($params['minor_revive_to']) ? $params['minor_revive_to'] : 100;
    // major_revive_percent, default 5%
    $major_revive_percent = isset($params['major_revive_percent']) ? $params['major_revive_percent'] : 5;
    $just_testing = isset($params['just_testing']) ? 'true' : 'false';
    $major_hour = 3;
    // Hour for the major revive.
    $revive_amount = 0;
    // Initial.
    /* New schedule should be:
       1: revive to 100
       2: revive to 100 (probably 0)
       3: revive 150, (250 total) to a max of 80% of total, ~2500.
       4: revive to 100 (almost certainly no more)
       5: revive to 100 (almost certainly no more)
       6: revive 150, (400 total) to a max of 80% of total, ~2500
       7: ...etc.
       */
    // SQL pulls.
    $db = new DBAccess();
    // Determine the total dead (& confirmed).
    $sel_dead = 'select count(*) from players where health<1 and confirmed=1';
    $dead_count = $db->QueryItem($sel_dead);
    // If none dead, return false.
    if (!$dead_count) {
        return array(0, 0);
    }
    // Determine the total confirmed.
    $sel_total_active = 'select count(*) from players where confirmed=1';
    $total_active = $db->QueryItem($sel_total_active);
    // Calc the total alive.
    $total_alive = $total_active - $dead_count;
    // Determine major or minor based on the hour.
    $sel_current_time = "SELECT amount from time where time_label='hours'";
    $current_time = $db->QueryItem($sel_current_time);
    assert(is_numeric($current_time));
    $major = false;
    if ($current_time % $major_hour == 0) {
        $major = true;
    }
    // If minor, and total_alive is more than minor_revive_to-1, return 0/total.
    if (!$major) {
        // minor
        if ($total_alive > $minor_revive_to - 1) {
            // minor_revive_to already met.
            return array(0, $dead_count);
        } else {
            // else revive minor_revive_to - total_alive.
            $revive_amount = floor($minor_revive_to - $total_alive);
        }
    } else {
        // major.
        $percent_int = floor($major_revive_percent / 100 * $total_active);
        if ($dead_count < $percent_int) {
            // If major, and total_dead is less than target_num (major_revive_percent*total, floored)
            // just revive those that are dead.
            $revive_amount = $dead_count;
        } else {
            // Else revive target_num (major_revive_percent*total, floored)
            $revive_amount = $percent_int;
        }
    }
    //die();
    assert(isset($revive_amount));
    assert(isset($current_time));
    assert(isset($just_testing));
    assert(isset($dead_count));
    assert(isset($major));
    // Actually perform the revive on those integers.
    // Use the order by clause to determine who revives, by time, days and then by level, using the limit set previously.
    //select uname, player_id, level,floor(($major_revive_percent/100)*$total_active) days, resurrection_time from players where confirmed = 1 AND health < 1 ORDER BY abs(8 - resurrection_time) asc, level desc, days asc
    $select = "select player_id from players where confirmed = 1 AND health < 1 ORDER BY abs(" . intval($current_time) . "\n        \t- resurrection_time) asc, level desc, days asc limit " . $revive_amount;
    $up_revive_players = "UPDATE players\n                    SET status = 0,\n                    health =\n                    \tCASE WHEN " . $just_testing . "\n                    \tTHEN health\n                    \tELSE\n                    \t\t(\n                    \t\tCASE WHEN class='White'\n                    \t\tTHEN (150+(level*3))\n                    \t\tELSE (100+(level*3)) END\n                    \t\t)\n                    \tEND\n                    WHERE\n                    player_id IN (" . $select . ")\n                  ";
    $db->Update($up_revive_players);
    $truly_revived = $db->getAffectedRows();
    // Return the 'revived/total' actually revived.
    return array($truly_revived, $dead_count);
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:90,代码来源:lib_deity.php

示例10: check

 /**
  * Checks whether an attack is legal or not.
  *
  * @return boolean
  **/
 function check()
 {
     $sql = new DBAccess();
     $attacker = $this->attacker;
     $target = $this->target;
     $possible = array('required_turns', 'ignores_stealth', 'self_use', 'clan_forbidden');
     //Initializes all the possible param indexes.
     foreach ($possible as $loop_index) {
         ${$loop_index} = isset($this->params[$loop_index]) ? $this->params[$loop_index] : NULL;
     }
     if (!is_object($this->attacker)) {
         $this->error = 'Only Ninja can get close enough to attack.';
         return FALSE;
     } elseif (!is_object($this->target)) {
         $this->error = 'No valid target was found.';
         return FALSE;
     } elseif (!isset($this->params['required_turns'])) {
         $this->error = 'The required number of turns was not specified.';
         return FALSE;
     }
     $target_status = $target->getStatus();
     $second_interval_limiter_on_attacks = '.25';
     // Originally .2
     $sel_last_started_attack = "select player_id from players\n\t\t\twhere player_id = '" . intval($this->attacker->player_id) . "'\n\t\t\tand ((now() - interval '" . $second_interval_limiter_on_attacks . " second') >= last_started_attack) limit 1";
     $attack_later_than_limit = $sql->QueryItem($sel_last_started_attack);
     // Returns a player id if the enough time has passed, or else or false/null.
     if ($attack_later_than_limit) {
         // If not too soon, update the attack limit.
         update_last_attack_time($attacker->vo->player_id, $sql);
     }
     // updates the timestamp of the last_attacked column to slow excessive attacks.
     switch (true) {
         //  *** START OF ILLEGAL ATTACK ERROR LIST  ***
         case !$attack_later_than_limit:
             $this->error = "Even the fastest ninja cannot act more than four times a second.";
             return false;
             break;
         case $target->vo->uname == "":
             $this->error = "Your target does not exist.";
             return false;
             break;
         case $target->player_id == $attacker->player_id && !$self_use:
             $this->error = "Commiting suicide is a tactic reserved for samurai.";
             return false;
             break;
         case $attacker->vo->turns < $required_turns:
             $this->error = "You do not have enough turns to perform this action in this way.";
             return false;
             break;
         case isset($_SESSION) && $target->vo->ip == $_SESSION['ip'] && $_SESSION['ip'] != '127.0.0.1' && !$self_use:
             $this->error = "You can not attack a ninja from the same domain.";
             return false;
             break;
         case $target->vo->confirmed == 0:
             $this->error = "You can not attack an inactive ninja.";
             return false;
             break;
         case $target->vo->health < 1:
             $this->error = "Your target is a ghost.";
             return false;
             break;
         case $target_status['Stealth'] && !$ignores_stealth:
             // Attacks that ignore stealth will skip this.
             $this->error = "Your target is stealthed. You can only hit this ninja using certain techniques.";
             return false;
             break;
         case $clan_forbidden && ($target->vo->clan == $attacker->vo->clan && $attacker->vo->clan != "" && !$self_use):
             $this->error = "Your clan would outcast you if you attacked one of your own.";
             return false;
             break;
         case $target->vo->health > 0:
             return true;
             //  ***  ATTACK IS LEGAL ***
             break;
         default:
             //  *** CATCHALL ERROR MESSAGE ***
             $this->error = "There was a problem with your attack.";
             error_log('The problem catch-all for attackLegal object was triggered, which should not occur.');
             return false;
             break;
     }
 }
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:87,代码来源:AttackLegal.class.php


注:本文中的DBAccess::QueryItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。