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


PHP SQL::query_count方法代码示例

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


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

示例1: get_seat

 /**
  * get a seat if possible
  *
  * @param string to designate the target anchor
  * @param int the initial number of available seats
  * @return boolean TRUE if you there is enough room, FALSE otherwise
  */
 public static function get_seat($reference, $offer = 20)
 {
     global $context;
     // number of seats is not really managed
     if (!$offer || $offer < 3) {
         return TRUE;
     }
     // compute the number of confirmed attendees
     $query = "SELECT id FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "') AND (approved LIKE 'Y')";
     if (($approved = SQL::query_count($query)) && $approved >= $offer) {
         return FALSE;
     }
     // some seats are available
     return TRUE;
 }
开发者ID:rair,项目名称:yacs,代码行数:22,代码来源:enrolments.php

示例2: count_users_at

 /**
  * count users doing the same thing
  *
  * @param string reference of the handled object (e.g., 'article:123')
  * @param string description of the action (e.g., 'post' or 'like')
  * @return int total count of profiles for this anchor and action
  */
 public static function count_users_at($anchor, $action = NULL)
 {
     global $context;
     // limit the query to one anchor
     $where = "(anchor LIKE '" . SQL::escape($anchor) . "')";
     // for some actions only
     if (is_array($action)) {
         $where .= " AND (action IN ('" . implode("', '", $action) . "'))";
     } elseif ($action) {
         $where .= " AND (action LIKE '" . SQL::escape($action) . "')";
     }
     // the list of activities
     $query = "SELECT DISTINCT edit_id\tFROM " . SQL::table_name('activities') . " AS activities" . " WHERE " . $where . " AND (edit_id > 0)";
     // count records
     return SQL::query_count($query);
 }
开发者ID:rair,项目名称:yacs,代码行数:23,代码来源:activities.php

示例3: get

 /**
  * get one section
  *
  * @param int or string the id or nick name of the section
  * @param boolean TRUE to always fetch a fresh instance, FALSE to enable cache
  * @return the resulting $item array, with at least keys: 'id', 'title', 'description', etc.
  */
 public static function get($id, $mutable = FALSE)
 {
     global $context;
     $output = array();
     // sanity check
     if (!$id) {
         $output = NULL;
         return $output;
     }
     // ensure proper unicode encoding
     $id = (string) $id;
     $id = utf8::encode($id);
     // filter id from reference if parameter given that way
     if (substr($id, 0, 8) === 'section:') {
         $id = substr($id, 8);
     }
     // cache previous answers
     static $cache;
     if (!is_array($cache)) {
         $cache = array();
     }
     // cache hit, but only for immutable objects
     if (!$mutable && isset($cache[$id])) {
         return $cache[$id];
     }
     // search by id
     if (is_numeric($id)) {
         $query = "SELECT * FROM " . SQL::table_name('sections') . " AS sections" . " WHERE (sections.id = " . SQL::escape((int) $id) . ")";
         $output = SQL::query_first($query);
         // or look for given name of handle
     } else {
         $query = "SELECT * FROM " . SQL::table_name('sections') . " AS sections" . " WHERE (sections.nick_name LIKE '" . SQL::escape($id) . "') OR (handle LIKE '" . SQL::escape($id) . "')";
         $count = SQL::query_count($query);
         if ($count == 1) {
             // do the job
             $output = SQL::query_first($query);
         } elseif ($count > 1) {
             // result depending language give by $context['page_language']
             if (!isset($_SESSION['surfer_language']) || $_SESSION['surfer_language'] == 'none') {
                 $language = $context['language'];
             } else {
                 $language = $_SESSION['surfer_language'];
             }
             $result = SQL::query($query);
             while ($item = SQL::fetch($result)) {
                 $output = $item;
                 // return last by default
                 if ($item['language'] == $language) {
                     $output = $item;
                     break;
                 }
             }
         }
     }
     // save in cache
     if (is_array($output) && isset($output['id']) && count($cache) < 1000) {
         $cache[$id] = $output;
     }
     // return by reference
     return $output;
 }
开发者ID:rair,项目名称:yacs,代码行数:68,代码来源:sections.php

示例4: invite

 /**
  * enroll one user
  *
  * This function ensure that an invited person has been enrolled to this event.
  *
  * @see articles/invite.php
  *
  * @param int id of the enrolled person
  */
 function invite($id)
 {
     global $context;
     // force enrolment only if required
     if (!isset($_REQUEST['force_enrolment']) || $_REQUEST['force_enrolment'] != 'Y') {
         return;
     }
     // get matching profile
     if (($user = Users::get($id)) && is_callable(array($this->anchor, 'get_reference'))) {
         // if there is no enrolment record yet
         $query = "SELECT id FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . SQL::escape($this->anchor->get_reference()) . "') AND (user_id = " . SQL::escape($user['id']) . ")";
         if (!SQL::query_count($query)) {
             // fields to save
             $query = array();
             // reference to the meeting page
             $query[] = "anchor = '" . SQL::escape($this->anchor->get_reference()) . "'";
             // direct enrolment
             $query[] = "approved = 'Y'";
             // save user id
             $query[] = "user_id = " . SQL::escape($user['id']);
             // save user e-mail address
             $query[] = "user_email = '" . SQL::escape($user['email']) . "'";
             // insert a new record
             $query = "INSERT INTO " . SQL::table_name('enrolments') . " SET " . implode(', ', $query);
             SQL::query($query);
         }
     }
 }
开发者ID:rair,项目名称:yacs,代码行数:37,代码来源:event.php

示例5: count_tables

 /**
  * count tables in database
  *
  * @param string database name
  * @param resource connection to the database server, if any
  * @return int number of tables, or FALSE on failure
  */
 public static function count_tables($name = NULL, $connection = NULL)
 {
     global $context;
     // sanity check
     if (!$name) {
         $name = $context['database'];
     }
     // use the default connection
     if (!$connection) {
         // we do need a connection to the database
         if (!isset($context['connection']) || !$context['connection']) {
             return FALSE;
         }
         $connection = $context['connection'];
     }
     // the query to list tables
     $query = 'SHOW TABLES';
     // count tables
     return SQL::query_count($query, TRUE, $connection);
 }
开发者ID:rair,项目名称:yacs,代码行数:27,代码来源:sql.php

示例6: toggle

 /**
  * toggle a membership
  *
  * The father parameter is used to specialize a membership to a sub-category.
  *
  * @param string the anchor id (e.g., 'category:123')
  * @param string the member id (e.g., 'article:456')
  * @param string the father id, if any (e.g., 'category:456')
  * @return string either a null string, or some text describing an error to be inserted into the html response
  *
  * @see categories/select.php
  * @see users/track.php
  **/
 public static function toggle($anchor, $member, $father = NULL)
 {
     global $context;
     // anchor cannot be empty
     if (!$anchor) {
         return i18n::s('An anchor is required for this operation.');
     }
     // member cannot be empty
     if (!$member) {
         return i18n::s('A member is required for this operation.');
     }
     // clear the cache
     Cache::clear(array($anchor, $member, $father));
     // check if the membership already exists
     $query = "SELECT id  FROM " . SQL::table_name('members') . " WHERE (anchor LIKE '" . SQL::escape($anchor) . "') AND (member LIKE '" . SQL::escape($member) . "') LIMIT 0, 1";
     // delete an existing membership
     if (SQL::query_count($query)) {
         $query = "DELETE FROM " . SQL::table_name('members') . " WHERE (anchor LIKE '" . SQL::escape($anchor) . "') AND (member LIKE '" . SQL::escape($member) . "')";
         // insert one new record
     } else {
         // boost further queries
         list($member_type, $member_id) = explode(':', $member, 2);
         // insert one new record
         $query = "INSERT INTO " . SQL::table_name('members') . " SET" . " anchor='" . SQL::escape($anchor) . "'," . " member='" . SQL::escape($member) . "'," . " member_type='" . SQL::escape($member_type) . "'," . " member_id='" . SQL::escape($member_id) . "'," . " edit_date='" . SQL::escape(gmstrftime('%Y-%m-%d %H:%M:%S')) . "'";
     }
     // update the database
     if (SQL::query($query) === FALSE) {
         return NULL;
     }
     // delete the father membership, if any
     if ($father) {
         $query = "DELETE FROM " . SQL::table_name('members') . " WHERE (anchor LIKE '" . SQL::escape($father) . "') AND (member LIKE '" . SQL::escape($member) . "')";
         SQL::query($query);
     }
     // end of job
     return NULL;
 }
开发者ID:rair,项目名称:yacs,代码行数:50,代码来源:members.php

示例7: prove_presence_of

 /**
  * visits prove the presence of one user
  *
  * @param int id of the visiting user
  * @param int maximum age of visit, in seconds
  * @return TRUE if the user is present, FALSE otherwise
  */
 public static function prove_presence_of($user, $timeout = 3600)
 {
     global $context;
     // sanity check
     if (!$user) {
         return FALSE;
     }
     // only consider recent presence records
     $threshold = gmstrftime('%Y-%m-%d %H:%M:%S', time() - $timeout);
     // select matching links
     $query = "SELECT id FROM " . SQL::table_name('visits') . " AS visits" . " WHERE (visits.user_id = " . SQL::escape($user) . ")" . "\tAND (visits.edit_date >= '" . SQL::escape($threshold) . "')" . " LIMIT 1";
     if (!($result = SQL::query_count($query))) {
         return FALSE;
     }
     // we have at least one recent record
     return TRUE;
 }
开发者ID:rair,项目名称:yacs,代码行数:24,代码来源:visits.php

示例8: WHERE

 }
 // count links edited this year
 $query = "SELECT id FROM " . SQL::table_name('links') . " WHERE (anchor IN ('" . implode("', '", $anchors) . "')) AND (edit_date LIKE '" . $current_year . "%')";
 if ($count = SQL::query_count($query)) {
     $fields_y[] = "`links`=" . $count;
     $total_y += $count;
 }
 // count links attached to private anchors
 $query = "SELECT id FROM " . SQL::table_name('links') . " WHERE (anchor IN ('" . implode("', '", $anchors_private) . "'))";
 if ($count = SQL::query_count($query)) {
     $fields[] = "`links_private`=" . $count;
     $total_private += $count;
 }
 // count private links edited this year
 $query = "SELECT id FROM " . SQL::table_name('links') . " WHERE (anchor IN ('" . implode("', '", $anchors_private) . "')) AND (edit_date LIKE '" . $current_year . "%')";
 if ($count = SQL::query_count($query)) {
     $fields_y[] = "`links_private`=" . $count;
     $total_private_y += $count;
 }
 // total number of items in this section
 $fields[] = "`total`=" . $total;
 $fields[] = "`total_private`=" . $total_private;
 // add a record for this section
 $query = "INSERT INTO " . SQL::table_name('stat_sections') . ' SET ' . implode(', ', $fields);
 $records += SQL::query($query);
 // total number of items in this section
 $fields_y[] = "`total`=" . $total_y;
 $fields_y[] = "`total_private`=" . $total_private_y;
 // add a record for things edited during current year
 $query = "INSERT INTO " . SQL::table_name('stat_sections_' . $current_year) . ' SET ' . implode(', ', $fields);
 SQL::query($query);
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:dashboard.php


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