/**
  * Fetch the result
  * @param resource $result
  * @param int|NULL $arrayIndexEndValue
  * @return array
  */
 function _fetch($result, $arrayIndexEndValue = NULL)
 {
     if ($this->use_prepared_statements != 'Y') {
         return parent::_fetch($result, $arrayIndexEndValue);
     }
     $output = array();
     if (!$this->isConnected() || $this->isError() || !$result) {
         return $output;
     }
     // Prepared stements: bind result variable and fetch data
     $stmt = $result;
     $meta = mysqli_stmt_result_metadata($stmt);
     $fields = mysqli_fetch_fields($meta);
     /**
      * Mysqli has a bug that causes LONGTEXT columns not to get loaded
      * Unless store_result is called before
      * MYSQLI_TYPE for longtext is 252
      */
     $longtext_exists = false;
     foreach ($fields as $field) {
         if (isset($resultArray[$field->name])) {
             $field->name = 'repeat_' . $field->name;
         }
         // Array passed needs to contain references, not values
         $row[$field->name] = "";
         $resultArray[$field->name] =& $row[$field->name];
         if ($field->type == 252) {
             $longtext_exists = true;
         }
     }
     $resultArray = array_merge(array($stmt), $resultArray);
     if ($longtext_exists) {
         mysqli_stmt_store_result($stmt);
     }
     call_user_func_array('mysqli_stmt_bind_result', $resultArray);
     $rows = array();
     while (mysqli_stmt_fetch($stmt)) {
         $resultObject = new stdClass();
         foreach ($resultArray as $key => $value) {
             if ($key === 0) {
                 continue;
                 // Skip stmt object
             }
             if (strpos($key, 'repeat_')) {
                 $key = substr($key, 6);
             }
             $resultObject->{$key} = $value;
         }
         $rows[] = $resultObject;
     }
     mysqli_stmt_close($stmt);
     if ($arrayIndexEndValue) {
         foreach ($rows as $row) {
             $output[$arrayIndexEndValue--] = $row;
         }
     } else {
         $output = $rows;
     }
     if (count($output) == 1) {
         if (isset($arrayIndexEndValue)) {
             return $output;
         } else {
             return $output[0];
         }
     }
     return $output;
 }
 /**
  * @brief triggerAroundmapInsert에서 호출하는 함수. 단, sphinx 모듈 사용하지 않을시에만, \n
  * DB에 등록된 좌표들을 기준으로 거리를 계산하여 결과 값 리턴해준다.\n
  * @param $document_srl 문서 번호
  * @param $lat 위도
  * @param $lon 경도
  * @return 현재 위치  주변의 지표를 거리로 계산한 지표 리스트
  */
 function getAroundmapListMysql($document_srl, $lat, $lon)
 {
     $db_info = Context::getDBInfo();
     $sql = "select *, (sqrt((69.1 * abs({$lat} - lat)) * (69.1 * abs({$lat} - lat)) + (53 * abs({$lon} - lon)) * (53 * abs({$lon} - lon)))) * 1.609344 as distance from " . $db_info->db_table_prefix . "_aroundmap having document_srl != " . $document_srl . " order by distance ASC limit 10";
     $mysqlObj = new DBMysql();
     $result = $mysqlObj->_query($sql);
     $output = $mysqlObj->_fetch($result);
     if (!is_array($output)) {
         $array[] = $output;
         return $array;
     } else {
         return $output;
     }
 }