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


PHP Stats::storeDifference方法代码示例

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


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

示例1: query

 /**
  * executes query
  *
  * @param string $sql
  * @return result
  */
 public function query($sql)
 {
     $sqlDebug = defined("DEBUG") && DEBUG && isset($_REQUEST["sql_debug"]);
     $sql = $sql;
     if ($sqlDebug) {
         $stats = new Stats();
     }
     $this->querycount++;
     $res = mysql_query($sql, $this->connection) or $this->error(mysql_error(), $sql);
     if ($sqlDebug) {
         $stats->storeDifference();
         echo "\n<!--\n";
         echo "Query #{$this->querycount}: {$sql}\n";
         echo "Memory used: {$stats->memUsedFmted} bytes\n";
         echo "Time spent: {$stats->timeSpent} seconds\n";
         echo "-->\n";
     }
     return $res;
 }
开发者ID:krillo,项目名称:motiomera,代码行数:25,代码来源:DB.php

示例2: loadByIds

 /**
  * Loads a lot of objects at a time. Used to avoid multiple loadById calls. This saves lots of queries when using functions such as lister.
  *
  * @param array $ids array of ids to load
  * @param string $table the table from which to load the objects (ie the name of the class)
  * @param string $field which field to use for matching the data in the ids array (most likely the id field)
  * @param string $order used if any sorting is needed (added to the sql query)
  * @uses TABLEPREFIX to get the correct table name (prefix + supplied table name)
  * @uses DB::getBufferObjects load buffered objects (makes sure that an object doesn't need to be loaded twice on the same pageload, this saves queries)
  * @uses Mem::get check if the object is already in the memcache (if it is, we don't need to load it from the database)
  * @uses DB::query runs the select query from the database and return the matching rows
  * @uses function __getObj gets the needed data and creates the object
  * @uses DB::setBufferObjects adds the loaded object to the buffer to avoid loading it again in the future
  * @uses Misc::arrayKeyMerge() to merge the objects loaded by buffer or memcache with those loaded from database
  * @return array an array of objects
  */
 protected static function loadByIds($IDs, $objName, $field = "id", $orderBy = null)
 {
     global $db;
     $loadDebug = defined("DEBUG") && DEBUG && isset($_GET["load_debug"]);
     $bufferObjects = $db->getBufferObjects();
     $result = array();
     if ($loadDebug) {
         $stats = new Stats();
         $stats->numIDs = count($IDs);
         $stats->sql = "<none generated>";
     }
     // Check local memory storage ("buffer") for the IDs requested.
     foreach ($IDs as $idx => $objID) {
         if (isset($bufferObjects[$objName][$objID])) {
             $result[$objID] = $bufferObjects[$objName][$objID];
             unset($IDs[$idx]);
         }
     }
     if ($loadDebug) {
         $stats->numIDsFromCache = count($result);
     }
     // Fetch any remaining objects from the database.
     if ($IDs) {
         // Ascertain that the IDs are integers.
         $intIDs = array();
         foreach ($IDs as $objID) {
             $intIDs[] = (int) $objID;
         }
         // Construct SQL
         $sql = sprintf("select * from %s where %s in (%s)", self::TABLEPREFIX . strtolower($objName), $field, implode(",", $intIDs));
         if ($orderBy) {
             $sql .= " order by {$orderBy}";
         }
         if ($loadDebug) {
             $stats->sql = $sql;
         }
         // Fetch objects and store in local memory ("buffer").
         $res = $db->query($sql);
         while ($row = mysql_fetch_assoc($res)) {
             $objID = (int) $row["id"];
             $obj = self::__getObj($objName, $row);
             $db->setBufferObjects($obj, $objName);
             $result[$objID] = $obj;
         }
     }
     // Wouldn't this be awesome? It would. But we can't, because a lot of
     // the code relies on being able to pass in any number of IDs and only
     // get existing objects back. <profanities />
     /* $missingIDs = array_diff(array_keys($result), $IDs);
        if ($missingIDs) {
       	throw new ObjectsNotFoundException(implode(", ", $missingIDs));
        } */
     if ($loadDebug) {
         $stats->storeDifference();
         echo "\n<!--\n";
         echo "Load {$stats->numIDs} {$objName} objects\n";
         echo "{$stats->numIDsFromCache} objects in cache.\n";
         echo "SQL: {$stats->sql}\n";
         echo $stats->numIDs - count($result) . " missing objects.\n";
         echo "Memory used: {$stats->memUsedFmted} bytes\n";
         echo "Time spent: {$stats->timeSpent} seconds\n";
         echo "-->\n";
     }
     return $result;
 }
开发者ID:krillo,项目名称:motiomera,代码行数:81,代码来源:Mobject.php


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