本文整理匯總了PHP中DataBase::fetch方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataBase::fetch方法的具體用法?PHP DataBase::fetch怎麽用?PHP DataBase::fetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DataBase
的用法示例。
在下文中一共展示了DataBase::fetch方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_group
/**
* 獲取指定群信息
* @UserFunction(method = GET)
* @CheckLogin
*/
function get_group(Integer $id)
{
$db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
$user_id = getCurrentUserId();
$group = $db->fetch('SELETE * FROM `group` WHERE `id` = ?', $id);
$group['users'] = $db->fetchAll('SELECT a.`id`, a.`username`, a.`portrait` FROM `user` AS a INNER JOIN `group_user` AS b ON b.user_id=a.id WHERE b.group_id = ?', $id);
return $group;
}
示例2: delete_friend
/**
* 刪除好友數據
* @UserFunction(method = GET|POST)
* @CheckLogin
*/
function delete_friend(Integer $id)
{
$db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
$my_friend_status = $db->fetch('SELECT `status` FROM `friend` WHERE `user_id` = ? AND `friend_id` = ?', getCurrentUserId(), $id);
$other_friend_status = $db->fetch('SELECT `status` FROM `friend` WHERE `user_id` = ? AND `friend_id` = ?', $id, getCurrentUserId());
if ($my_friend_status && $other_friend_status) {
if ($my_friend_status['status'] == 1) {
//我們是好友
$db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', getCurrentUserId(), $id);
$db->exec('UPDATE `friend` SET `status` = 5 WHERE `user_id`=? AND `friend_id`=?;', $id, getCurrentUserId());
} else {
if ($my_friend_status['status'] == 2) {
// 刪除請求
$db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', getCurrentUserId(), $id);
$db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', $id, getCurrentUserId());
} else {
if ($my_friend_status['status'] == 3) {
// 刪除請求
$db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', getCurrentUserId(), $id);
$db->exec('UPDATE `friend` SET `status` = 4 WHERE `user_id`=? AND `friend_id`=?;', $id, getCurrentUserId());
} else {
throw new ProException('unknow error', 305);
}
}
}
} else {
if ($my_friend_status) {
$db->exec('DELETE FROM `friend` WHERE `user_id`=? AND `friend_id`=?;', getCurrentUserId(), $id);
} else {
throw new ProException('unknow error', 306);
}
}
}
示例3: profile
/**
* 獲取某人用戶資料
* @UserFunction(method = GET)
* @CheckLogin
*/
function profile(Integer $id)
{
$db = new DataBase(DB_DNS, DB_USER, DB_PASSWORD);
$user = $db->fetch('SELECT `id`, `username`, `portrait` FROM `user` WHERE `id` = ?', $id);
if ($user) {
return $user;
} else {
throw new ProException('user not found', 109);
}
}