当前位置: 首页>>代码示例>>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;未经允许,请勿转载。