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


PHP debug::get_microtime方法代码示例

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


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

示例1: query

 /**
  * This will run SQL query and return structured data
  *
  * @param string $sql
  * @param mixed $key
  * @param array $options
  * @return array
  */
 public function query($sql, $key = null, $options = [])
 {
     $result = ['success' => false, 'sql' => $sql, 'error' => [], 'errno' => 0, 'num_rows' => 0, 'affected_rows' => 0, 'rows' => [], 'key' => $key, 'structure' => [], 'time' => null, 'last_insert_id' => 0];
     // start time
     $result['time'] = debug::get_microtime();
     // cache id
     $crypt_object = new crypt();
     $cache_id = !empty($options['cache_id']) ? $options['cache_id'] : 'db_query_' . $crypt_object->hash($sql . serialize($key));
     // if we cache this query
     if (!empty($options['cache'])) {
         $cache_object = new cache($this->connect_options['cache_link']);
         $cached_result = $cache_object->get($cache_id);
         if ($cached_result !== false) {
             return $cached_result;
         }
     }
     // quering regular query first
     if (empty($options['multi_query'])) {
         $resource = mysqli_query($this->db_resource, $sql);
         if (!$resource) {
             $this->error_overrides($result, mysqli_errno($this->db_resource), mysqli_error($this->db_resource));
         } else {
             $result['affected_rows'] += mysqli_affected_rows($this->db_resource);
             if ($resource !== true) {
                 $result['num_rows'] += mysqli_num_rows($resource);
                 $result['structure'] = $this->field_structures($resource);
             }
             if ($result['num_rows'] > 0) {
                 while ($rows = mysqli_fetch_assoc($resource)) {
                     // casting types
                     $data = [];
                     foreach ($rows as $k => $v) {
                         $data[$k] = $this->process_value_as_per_type($v, $result['structure'][$k]['type']);
                     }
                     // assigning keys
                     if (!empty($key)) {
                         array_key_set_by_key_name($result['rows'], $key, $data);
                     } else {
                         $result['rows'][] = $data;
                     }
                 }
             }
             if ($resource !== true) {
                 mysqli_free_result($resource);
             }
             $result['success'] = true;
         }
     } else {
         // multi query
         $resource = mysqli_multi_query($this->db_resource, $sql);
         if (!$resource) {
             $result['error'][] = 'Db Link ' . $this->db_link . ': ' . mysqli_error($this->db_resource);
             $result['errno'] = mysqli_errno($this->db_resource);
             // we log this error message
             // todo: process log policy here
             error_log('Query error: ' . implode(' ', $result['error']) . ' [' . $sql . ']');
         } else {
             $result['affected_rows'] += mysqli_affected_rows($this->db_resource);
             do {
                 if ($result_multi = mysqli_store_result($this->db_resource)) {
                     if ($result_multi) {
                         $result['num_rows'] += $num_rows = mysqli_num_rows($result_multi);
                         $result['structure'] = $this->field_structures($result_multi);
                     } else {
                         $num_rows = 0;
                         $result['error'][] = 'Db Link ' . $this->db_link . ': Multi query error!';
                         $result['errno'] = 1;
                         // we log this error message
                         // todo: process log policy here
                         error_log('Query error: ' . implode(' ', $result['error']) . ' [' . $sql . ']');
                     }
                     if ($num_rows > 0) {
                         while ($rows = mysqli_fetch_assoc($result_multi)) {
                             // casting types
                             $data = [];
                             foreach ($rows as $k => $v) {
                                 $data[$k] = $this->process_value_as_per_type($v, $result['structure'][$k]['type']);
                             }
                             // assigning keys
                             if (!empty($key)) {
                                 array_key_set_by_key_name($result['rows'], $key, $data);
                             } else {
                                 $result['rows'][] = $data;
                             }
                         }
                     }
                     mysqli_free_result($result_multi);
                 }
             } while (mysqli_more_results($this->db_resource) && mysqli_next_result($this->db_resource));
             if (empty($result['error'])) {
                 $result['success'] = true;
             }
//.........这里部分代码省略.........
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:101,代码来源:base.php


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