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


PHP DBC::getRecord方法代码示例

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


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

示例1: fromDBC

 /**
  * Attempts to construct a map based on given DBC, predicting what each field could possibly hold by way of sampling
  */
 public static function fromDBC(DBC $dbc, $attach = true)
 {
     $fields = $dbc->getFieldCount();
     $samples = $dbc->getRecordCount() > self::SAMPLES ? self::SAMPLES : $dbc->getRecordCount();
     $block = $dbc->getStringBlock();
     preg_match_all('#\\0#', $block, $matches, PREG_OFFSET_CAPTURE);
     $strings = array();
     foreach ($matches[0] as $offset) {
         $offset = (int) $offset[1] + 1;
         if ($offset < strlen($block) - 1) {
             $strings[$offset] = true;
         }
     }
     $matrix = array_fill(1, $fields, 0);
     for ($i = 0; $i < $samples; $i++) {
         $record = $dbc->getRecord($i);
         $values = $record->asArray();
         foreach ($values as $offset => $value) {
             if ($value < 0) {
                 $matrix[$offset] += 1 << 0;
             }
             if (self::isProbableFloat($value)) {
                 $matrix[$offset] += 1 << 8;
             }
             if (isset($strings[$value]) || $value === 0) {
                 $matrix[$offset] += 1 << 16;
                 if ($value !== 0) {
                     $matrix[$offset] |= 1 << 24;
                 }
             }
         }
     }
     $map = new self();
     for ($i = 1; $i <= $fields; $i++) {
         $probs = $matrix[$i];
         $int = ($probs & 0xff) / $samples;
         $flt = (($probs & 0xff00) >> 8) / $samples;
         $str = (($probs & 0xff0000) >> 16) / $samples;
         $strbit = ($probs & 0xff000000) >> 24;
         $field = 'field' . $i;
         if ($flt > 0.6) {
             $type = DBC::FLOAT;
         } else {
             if ($strbit > 0 && $str > 0.99) {
                 $type = DBC::STRING;
                 if ($i + DBC::LOCALIZATION <= $fields) {
                     $type = DBC::STRING_LOC;
                     for ($j = $i + 1; $j <= $i + DBC::LOCALIZATION; $j++) {
                         $probs = $matrix[$j];
                         $str = (($probs & 0xff0000) >> 16) / $samples;
                         $strbit = ($probs & 0xff000000) >> 24;
                         if ($str !== 1 || $strbit !== 0) {
                             $type = DBC::STRING;
                         }
                     }
                     if ($type === DBC::STRING_LOC) {
                         $i += DBC::LOCALIZATION;
                     }
                 }
             } else {
                 if ($int > 0.01) {
                     $type = DBC::INT;
                 } else {
                     $type = DBC::UINT;
                 }
             }
         }
         $map->add($field, $type);
     }
     if ($attach && $dbc->getMap() === null) {
         $dbc->attach($map);
     }
     return $map;
 }
开发者ID:xianyinchen,项目名称:EventAI-to-SmartAI,代码行数:77,代码来源:DBCMap.class.php

示例2: DBC

 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * @author	Tim Kurvers <tim@moonsphere.net>
 */
error_reporting(E_ALL | E_STRICT);
require '../lib/bootstrap.php';
/**
 * This example shows how to edit an existing a DBC-file
 */
// Open given DBC and given map (editing requires a writable DBC)
$dbc = new DBC('./dbcs/Sample.dbc', DBCMap::fromINI('./maps/Sample.ini'));
// Grab the first record
$rec = $dbc->getRecord(0);
// Dump the record in its initial state
$rec->dump(true);
// Read the points value (field 18 or 'points')
$points = $rec->getInt(18);
$points = $rec->getInt('points');
// Write the points value +1 (again through field 18 or 'points') and verify the record-dump
$rec->setInt(18, $points + 1);
$rec->setInt('points', $points + 1);
$rec->dump(true);
// Write a random string to the name field and verify the record-dump
$rec->setString('name', uniqid());
$rec->dump(true);
// Also, note how the string-block of the DBC file increases per string-write!
var_dump($dbc);
开发者ID:WyriMaps,项目名称:php-wow-dbc,代码行数:31,代码来源:edit.php


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