本文整理汇总了PHP中Database::sql2array方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::sql2array方法的具体用法?PHP Database::sql2array怎么用?PHP Database::sql2array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::sql2array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByIdsLoaded
public static function getByIdsLoaded($ids)
{
$out = array();
$tofetch = array();
if (is_array($ids)) {
foreach ($ids as $uid) {
$uid = (int) $uid;
if (!isset(self::$users[$uid])) {
if (!self::getFromCache($uid)) {
$tofetch[] = $uid;
}
}
}
if (count($tofetch)) {
$query = 'SELECT * FROM `users` WHERE `id` IN (' . implode(',', $tofetch) . ')';
$data = Database::sql2array($query, 'id');
}
foreach ($ids as $uid) {
if (!isset(self::$users[(int) $uid])) {
if (isset($data[$uid])) {
$tmp = new User($uid, $data[$uid]);
self::$users[$tmp->id] = $tmp;
self::putInCache($tmp->id);
unset($tmp);
}
}
}
foreach ($ids as $uid) {
if (isset(self::$users[$uid])) {
$out[$uid] = self::$users[$uid];
}
}
}
return $out;
}
示例2: getRightholders
function getRightholders()
{
$cond = new Conditions();
$per_page = 0;
if (isset($this->params['per_page'])) {
$per_page = (int) $this->params['per_page'];
}
$per_page = $per_page > 0 ? $per_page : 1;
$pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p';
$where = '';
$order = 'ORDER BY `id` DESC ';
$group_by = '';
$query = 'SELECT COUNT(1) FROM `rightholders` ' . $where . ' ' . $group_by . '';
$count = Database::sql2single($query);
$cond->setPaging($count, $per_page, $pagingName);
$limit = $cond->getLimit();
$limit = ' LIMIT ' . $limit;
$query = 'SELECT * FROM `rightholders`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit;
$data = Database::sql2array($query);
foreach ($data as &$row) {
$row['path'] = Config::need('www_path') . '/admin/rightholders/' . $row['id'];
}
$this->data['rightholders'] = $data;
$this->data['rightholders']['title'] = 'Правообладатели';
$this->data['rightholders']['count'] = $count;
$this->data['conditions'] = $cond->getConditions();
}
示例3: get_likes
function get_likes($params, &$data)
{
$ids = $_POST['ids'];
$to_check = array();
foreach ($ids as $event_id) {
if (is_numeric($event_id) && $event_id > 0) {
$to_check[$event_id] = $event_id;
}
}
if (count($to_check)) {
$res = Database::sql2array('SELECT `user_id`,`event_id` FROM `event_likes` WHERE `event_id` IN (' . implode(',', $to_check) . ')');
$uids = array();
foreach ($res as $row) {
$uids[$row['user_id']] = $row['user_id'];
}
if (count($uids)) {
$users = Users::getByIdsLoaded(array_keys($uids));
foreach ($res as $row) {
if (isset($users[$row['user_id']])) {
$data['likes'][$row['event_id']][$row['user_id']] = array('nickname' => $users[$row['user_id']]->data['nickname'], 'id' => $users[$row['user_id']]->data['id']);
if (CurrentUser::$id == $row['user_id']) {
$data['self'][$row['event_id']] = $row['user_id'];
}
}
}
}
}
foreach ($to_check as $event_id) {
if (!isset($data['likes'][$event_id])) {
$data['likes'][$event_id] = array();
}
}
$data['owner'] = CurrentUser::$id;
return $data;
}
示例4: getThreadList
function getThreadList() {
global $current_user;
$out = array();
$query = 'SELECT * FROM `users_messages_index` UMI
RIGHT JOIN `users_messages` UM ON UM.id = UMI.message_id
WHERE `id_recipient`=' . $current_user->id . ' AND `is_deleted`=0';
$messages = Database::sql2array($query);
// загрузили все сообщения вообще
// для каждого треда выбираем последнее сообщение
$messages_prepared = array();
$uids = array();
foreach ($messages as &$message) {
if (!isset($messages_prepared[$message['thread_id']])) {
$messages_prepared[$message['thread_id']]['newest']['time'] = 0;
$messages_prepared[$message['thread_id']]['oldest']['time'] = time() + 10000;
}
if ($messages_prepared[$message['thread_id']]['newest']['time'] < $message['time']) {
$messages_prepared[$message['thread_id']]['newest'] = $message;
$messages_prepared[$message['thread_id']]['html'] = $message['html'];
}
if ($message['is_new'])
$messages_prepared[$message['thread_id']]['is_new'] = 1;
if ($messages_prepared[$message['thread_id']]['oldest']['time'] > $message['time']) {
$messages_prepared[$message['thread_id']]['oldest'] = $message['time'];
$messages_prepared[$message['thread_id']]['subject'] = $message['subject'];
}
$messages_prepared[$message['thread_id']]['members'][$message['id_recipient']] = $message['id_recipient'];
$messages_prepared[$message['thread_id']]['members'][$message['id_author']] = $message['id_author'];
$messages_prepared[$message['thread_id']]['thread_id'] = $message['thread_id'];
}
foreach ($messages_prepared as $thread_id => &$mess) {
$mess['oldest'] = date('Y/m/d H:i:s', $mess['oldest']);
$tmpmess = $mess['newest'];
$tmpmess['oldest'] = $mess['oldest'];
$tmpmess['newest'] = date('Y/m/d H:i:s', $mess['newest']['time']);
$tmpmess['time'] = date('Y/m/d H:i:s', $tmpmess['time']);
$tmpmess['subject'] = $mess['subject'];
$tmpmess['is_new'] = isset($mess['is_new']) ? 1 : 0;
foreach ($mess['members'] as $uid) {
if ($current_user->id != $uid)
$tmpmess['members'][] = array(
'id' => $uid
);
$uids[$uid] = $uid;
}
$out[] = $tmpmess;
}
$users = Users::getByIdsLoaded($uids);
foreach ($users as $user) {
$this->data['users'][$user->id] = $user->getListData();
}
$this->data['messages'] = $out;
}
示例5: getByIdsLoaded
public static function getByIdsLoaded($ids)
{
$out = array();
$tofetch = array();
if (is_array($ids)) {
foreach ($ids as $uid) {
if (!isset(self::$persons[(int) $uid])) {
$tofetch[] = $uid;
}
}
if (count($tofetch)) {
$query = 'SELECT * FROM `persons` WHERE `id` IN (' . implode(',', $tofetch) . ')';
$data = Database::sql2array($query, 'id');
}
foreach ($ids as $id) {
if (!isset(self::$persons[(int) $id])) {
if (isset($data[$id])) {
$tmp = new Person($id, $data[$id]);
self::$persons[$tmp->id] = $tmp;
unset($tmp);
} else {
//self::$persons[$id] = new Person($id); // todo
}
}
}
foreach ($ids as $id) {
if (isset(self::$persons[$id])) {
$out[$id] = self::$persons[$id];
}
}
}
return $out;
}
示例6: getCityList
function getCityList()
{
$country = isset($_POST['country_id']) ? (int) $_POST['country_id'] : 1;
$this->data['city_list'] = Database::sql2array('SELECT `id`,`name` FROM `lib_city` WHERE `country_id`=' . $country . ' LIMIT 1000', 'id');
$this->data['country_id'] = $country;
$this->data['city_id'] = Database::sql2single('SELECT `id` FROM `lib_city` WHERE `country_id`=' . $country . ' LIMIT 1');
}
示例7: getByIdsLoaded
public static function getByIdsLoaded($uids)
{
$data = Database::sql2array('SELECT * FROM `user` WHERE `id` IN(' . implode(',', $uids) . ')');
$users = array();
foreach ($data as $row) {
$users[$row['id']] = new User($row['id'], $row);
}
return $users;
}
示例8: sqlLoad
public static function sqlLoad(array $ids, array $users)
{
if (count($ids)) {
$query = 'SELECT * FROM `user` WHERE `id` IN (' . implode(',', $ids) . ')';
$data = Database::sql2array($query, 'id');
foreach ($data as $row) {
$users[$row['id']] = self::add($row['id'], $row);
}
}
return $users;
}
示例9: getTemplateFields
function getTemplateFields($template_id)
{
$query = 'SELECT * FROM `lib_event_templates` LET
LEFT JOIN `lib_event_templates_fields` LETF ON LET.id=LETF.template_id
LEFT JOIN `lib_event_templates_fields_types` LETFT ON LETFT.id=LETF.`type`
WHERE LET.id=' . $template_id . ' ORDER BY pos';
$data = Database::sql2array($query);
foreach ($data as $field) {
$out[$field['type_name']] = array('type' => $field['type_name'], 'important' => $field['important'], 'title' => $field['title'], 'field_id' => $field['field_id'], 'pos' => $field['pos']);
}
return $out;
}
示例10: _list
function _list($opts)
{
$data = array();
$has_paging = !isset($opts['no_paging']);
$show_sortings = isset($opts['show_sortings']);
$per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
$per_page = min(100, max(1, (int) $per_page));
$cond = new Conditions();
$cond->setSorting(array('time' => array('order' => 'desc', 'title' => 'по дате')), array('time' => array('order' => 'desc', 'title' => 'по дате')));
$cond->setPaging(100000, $per_page);
$where = array('parent_id=0');
if (isset($opts['where'])) {
foreach ($opts['where'] as $w) {
$where[] = $w;
}
}
$order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
$limit = $cond->getLimit();
$query = 'SELECT * FROM `comments`
WHERE (' . implode(' AND ', $where) . ')
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
$comments = Database::sql2array($query, 'id');
$pids = array();
$uids = array();
foreach ($comments as $comment) {
$pids[$comment['id']] = $comment['id'];
$uids[$comment['user_id']] = $comment['user_id'];
}
if (count($pids)) {
$query = 'SELECT * FROM `comments` WHERE `thread` IN (' . implode(',', $pids) . ') ORDER BY `thread`,`id`';
$nextlevel = Database::sql2array($query, 'id');
$comments += $nextlevel;
foreach ($comments as $comment) {
$uids[$comment['user_id']] = $comment['user_id'];
}
if (count($uids)) {
$users = Users::getByIdsLoaded($uids);
} else {
$users = array();
}
foreach ($comments as &$comment) {
if (!isset($users[$comment['user_id']])) {
continue;
}
$comment['user'] = $users[$comment['user_id']];
$parents[$comment['parent_id']][$comment['id']] = $comment;
uasort($parents[$comment['parent_id']], 'x_sort_comment');
}
$comments = $this->build_tree($parents, 0);
}
return $comments;
}
示例11: write
function write() {
global $current_user;
if (!$current_user->authorized)
throw new Exception('Access Denied');
$id_author = $current_user->id;
$to_users = isset(Request::$post['to']) ? Request::$post['to'] : array($current_user->id);
if (strstr($to_users, ','))
$to_users = explode(',', $to_users);
if (!is_array($to_users))
$to_users = array($to_users);
foreach ($to_users as $id) {
if (strstr($id, ',')) {
$t_to_users = explode(',', $id);
foreach ($t_to_users as $n) {
$to_users_p[(int) $n] = (int) $n;
}
}
else $to_users_p[$id] = (int)$id;
}
$to_users = $to_users_p;
$subject = isset(Request::$post['subject']) ? Request::$post['subject'] : 'Без темы';
$body = isset(Request::$post['body']) ? Request::$post['body'] : false;
$subject = prepare_review($subject, '');
$body = prepare_review($body, '');
if (!$body)
throw new Exception('body!');
$time = time();
$thread_id = isset(Request::$post['thread_id']) ? Request::$post['thread_id'] : false;
if ($thread_id) {
// а можно ли писать в этот тред этому человеку?
$query = 'SELECT DISTINCT id_recipient FROM `users_messages_index` WHERE `thread_id`=' . $thread_id;
$usrs = Database::sql2array($query);
$found = false;
$to_users = array();
if ($usrs) {
foreach ($usrs as $usr) {
if ($usr['id_recipient'] == $current_user->id)
$found = true;
$to_users[$usr['id_recipient']] = $usr['id_recipient'];
}
}
if (!$found)
throw new Exception('You cant post to thread #' . $thread_id);
}
$to_users[$current_user->id] = $current_user->id;
$this->sendMessage($id_author, $to_users, $subject, $body, $time, $thread_id);
}
示例12: getBookShelf
function getBookShelf() {
if ($this->shelfLoaded)
return $this->shelf;
$query = 'SELECT * FROM `users_bookshelf` WHERE `id_user`=' . $this->id;
$array = Database::sql2array($query);
$out = array();
foreach ($array as $row) {
$out[$row['bookshelf_type']][$row['id_book']] = $row;
}
$this->shelfLoaded = true;
$this->shelf = $out;
return $this->shelf;
}
示例13: saveSettings
function saveSettings()
{
require_once $filename = dirname(Config::need('xslt_files_path')) . '/localconfig.php';
global $local_config;
$query = 'SELECT * FROM `settings`';
$arr = Database::sql2array($query);
$local_config['-----------------'] = '-----------------';
foreach ($arr as $setting) {
$local_config[$setting['name']] = $setting['value'];
}
$s = var_export($local_config, true);
file_put_contents($filename, '<?php $local_config = ' . $s . ";\n" . '//some settings generated by setting module');
}
示例14: getDataFromUids
function getDataFromUids($ids)
{
if (!count($ids)) {
return array();
}
$out = array();
$query = 'SELECT * FROM `users` WHERE `id` IN (' . implode(',', $ids) . ')';
$result = Database::sql2array($query);
foreach ($result as $userRow) {
$user = Users::getById($userRow['id'], $userRow);
/* @var $user User */
$out[$user->id] = array('id' => $user->id, 'nickname' => $user->getProperty('nickname'), 'picture' => $user->getProperty('picture') ? $user->id . '.jpg' : 'default.jpg', 'lastSave' => $user->getProperty('lastSave'));
}
return $out;
}
示例15: load
public function load()
{
if ($this->loaded) {
return;
}
$query = 'SELECT * FROM `magazines` M LEFT JOIN `book_magazines` BM
ON BM.id_magazine=M.id WHERE M.`id`=' . $this->id;
$this->data = Database::sql2row($query);
$query = 'SELECT * FROM `book_magazines` WHERE `id_magazine`=' . $this->id;
$books = Database::sql2array($query, 'id_book');
foreach ($books as $row) {
$this->books[$row['year']][$row['n']] = $row['id_book'];
}
$this->loaded = true;
}