當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataBase::fetchColumn方法代碼示例

本文整理匯總了PHP中DataBase::fetchColumn方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataBase::fetchColumn方法的具體用法?PHP DataBase::fetchColumn怎麽用?PHP DataBase::fetchColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataBase的用法示例。


在下文中一共展示了DataBase::fetchColumn方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: join_group

/**
* 加入群
* @UserFunction(method = GET|POST)
* @CheckLogin
*/
function join_group(Integer $id)
{
    $db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
    $user_id = getCurrentUserId();
    $group = $db->fetch('SELECT * FROM `group`  WHERE `id` = ?;', $id);
    if ($group) {
        if ($group['number'] >= $group['max_number']) {
            throw new ProException('group $id reach limit', 202);
        }
        if ($db->fetchColumn('SELECT count(*) FROM `group_user` WHERE `user_id`=? AND `group_id`=?', $user_id, $id) != 0) {
            throw new ProException('you have to join the $id group', 203);
        }
        $db->exec('INSERT INTO `group_user`(`group_id`, `user_id`, `role`) VALUES(?,?,0);', $id, $user_id);
        $db->exec('UPDATE `group` SET `number` = `number`+1  WHERE `id` = ?;', $id);
    } else {
        throw new ProException('group $id is not exists', 201);
    }
}
開發者ID:huashihongfeng,項目名稱:demo-server-php,代碼行數:23,代碼來源:GroupProcess.php

示例2: process_request_friend

/**
* 處理好友邀請
* @UserFunction(method = GET|POST)
* @CheckLogin
*/
function process_request_friend(Integer $id, Boolean $is_access)
{
    $currentUserId = getCurrentUserId();
    $db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
    $my_friend_status = $db->fetch('SELECT `status` FROM `friend` WHERE `user_id` = ? AND `friend_id` = ?', $currentUserId, $id);
    $other_friend_status = $db->fetch('SELECT `status` FROM `friend` WHERE `user_id` = ? AND `friend_id` = ?', $id, $currentUserId);
    if ($my_friend_status && $other_friend_status && $my_friend_status['status'] == 3 && $other_friend_status['status'] == 2) {
        if ($is_access->val) {
            $db->exec('UPDATE `friend` SET `status` = 1 WHERE `user_id`=? AND `friend_id`=?;', $currentUserId, $id);
            $db->exec('UPDATE `friend` SET `status` = 1 WHERE `user_id`=? AND `friend_id`=?;', $id, $currentUserId);
            $user_name_1 = $db->fetchColumn('SELECT `username` FROM `user` WHERE `id` = ?', $currentUserId);
            $user_name_2 = $db->fetchColumn('SELECT `username` FROM `user` WHERE `id` = ?', $id);
            //向融雲IM server發送消息
            //$other_id = $id->val;
            ServerAPI::getInstance()->messagePublish($currentUserId, array($id->val), 'RC:InfoNtf', json_encode(array('message' => '你已添加了' . $user_name_1 . ',現在可以開始聊天了。')));
            ServerAPI::getInstance()->messagePublish($id->val, array($currentUserId), 'RC:InfoNtf', json_encode(array('message' => '你已添加了' . $user_name_2 . ',現在可以開始聊天了。')));
        } else {
            $db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', $currentUserId, $id);
            $db->exec('UPDATE `friend` SET `status` = 4 WHERE `user_id`=? AND `friend_id`=?;', $id, $currentUserId);
        }
    } else {
        throw new ProException('unknow error', 306);
    }
}
開發者ID:huashihongfeng,項目名稱:demo-server-php,代碼行數:29,代碼來源:FriendProcess.php

示例3: send_activatiton_code

/**
* 發送激活碼
* @UserFunction
*/
function send_activatiton_code(Mobile $mobile)
{
    $db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
    $code = 2000;
    if ($db->fetchColumn('SELECT count(*) FROM `activation_code` WHERE `mobile` = ?', $mobile) == 0) {
        $db->insert('INSERT INTO `activation_code` (`mobile`, `code`) values(?,?)', $mobile, $code);
    } else {
        $timestamp = $db->fetchColumn('SELECT `timestamp` FROM `activation_code` WHERE `mobile` = ?', $mobile);
        if (time() - $timestamp > 60000) {
            $db->exec('UPDATE `activation_code` SET `code` = ? WHERE `mobile` = ?', $code, $mobile);
        } else {
            throw new ProException('Activation code is sent too frequently', 107);
        }
    }
}
開發者ID:huashihongfeng,項目名稱:demo-server-php,代碼行數:19,代碼來源:UserProcess.php


注:本文中的DataBase::fetchColumn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。