public function result($a_type = null)
 {
     if (!$this->m_result or !$this->m_result instanceof mysqli_result) {
         return $this->m_result;
     }
     $r = array();
     do {
         $row = false;
         switch ($a_type) {
             default:
             case ZDatabase::RESULT_TYPE_NUM:
                 $row = $this->m_result->fetch_array(MYSQLI_NUM);
                 break;
             case ZDatabase::RESULT_TYPE_ASSOC:
                 $row = $this->m_result->fetch_array(MYSQLI_ASSOC);
                 break;
             case ZDatabase::RESULT_TYPE_BOTH:
                 $row = $this->m_result->fetch_array(MYSQLI_BOTH);
                 break;
             case ZDatabase::RESULT_TYPE_OBJECT:
                 $row = $this->m_result->fetch_object();
                 break;
             case ZDatabase::RESULT_TYPE_RAW:
                 return $this->m_result;
         }
         if (!$row) {
             break;
         }
         $r[] = $row;
     } while (1);
     return $r;
 }
Пример #2
0
 public function result($a_type = null, $a_arg = null)
 {
     if (!$this->m_result) {
         return $this->m_result;
     }
     if ($this->m_result->num_rows() === false) {
         return false;
     }
     $r = array();
     do {
         $row = false;
         switch ($a_type) {
             default:
             case Zoombi_Database::RESULT_TYPE_NUM:
                 $row = $this->m_result->fetch_array(MYSQLI_NUM);
                 break;
             case Zoombi_Database::RESULT_TYPE_ASSOC:
                 $row = $this->m_result->fetch_array(MYSQLI_ASSOC);
                 break;
             case Zoombi_Database::RESULT_TYPE_BOTH:
                 $row = $this->m_result->fetch_array(MYSQLI_BOTH);
                 break;
             case Zoombi_Database::RESULT_TYPE_OBJECT:
                 $row = func_num_args() > 1 ? $this->m_result->fetch_object(func_get_arg(1)) : $this->m_result->fetch_object();
                 break;
             case Zoombi_Database::RESULT_TYPE_RAW:
                 return $this->m_result;
         }
         if (!$row) {
             break;
         }
         $r[] = $row;
     } while (1);
     return $r;
 }
Пример #3
0
 /**
  * @en Get element from query result as an object
  * @ru Получить первую запись из ответа базы данных в виде объекта
  *
  * $database = new database(); # do not forget to declare defines before calling this class:
  *                             # > RUDE_DATABASE_USER
  *                             # > RUDE_DATABASE_PASS
  *                             # > RUDE_DATABASE_HOST
  *                             # > RUDE_DATABASE_NAME
  *
  * $database->query('SELECT * FROM users WHERE 1 = 1');
  *
  * $result = $database->get_object(); # stdClass Object
  *                                    # (
  *                                    #     [id] => 2
  *                                    #     [username] => manager
  *                                    #     [hash] => 0991b08461e5ce0ee0a038c104b5a6d3
  *                                    #     [salt] => nLpUwvzSpD5yoqXtqjvhtqwhJUsMFh8P
  *                                    #     [role_id] => 2
  *                                    # )
  *
  * @return mixed
  */
 public function get_object()
 {
     if ($object = $this->result->fetch_object()) {
         return $object;
     }
     return null;
 }
Пример #4
0
 /**
  * Returns the current row of a result set under HHVM
  * The problem was fetch_object creates new instance of a given class,
  * and attaches resulted key/value pairs after the class was constructed.
  *
  * @return  mixed
  */
 private function currentHHVM()
 {
     if ($this->_as_object === TRUE or is_string($this->_as_object)) {
         if ($this->_reflect_class === NULL) {
             // Create reflection class of given classname or stdClass
             $this->_reflect_class = new ReflectionClass(is_string($this->_as_object) ? $this->_as_object : 'stdClass');
         }
         // Support ORM with loaded, when the class has __set and __construct if its ORM
         if ($this->_reflect_class->hasMethod('__set') === TRUE && $this->_reflect_class->hasMethod('__construct') === TRUE) {
             // Get row as associated array
             $row = $this->_result->fetch_assoc();
             // Get new instance without constructing it
             $object = $this->_reflect_class->newInstanceWithoutConstructor();
             foreach ($row as $column => $value) {
                 // Trigger the class setter
                 $object->__set($column, $value);
             }
             // Construct the class with no parameters
             $object->__construct(NULL);
             return $object;
         } elseif (is_string($this->_as_object)) {
             // Return an object of given class name
             return $this->_result->fetch_object($this->_as_object, (array) $this->_object_params);
         } else {
             // Return an stdClass
             return $this->_result->fetch_object();
         }
     }
     // Get row as associated array
     return $this->_result->fetch_assoc();
 }
Пример #5
0
 /**
  * Get results
  * @return array
  */
 public function get_results()
 {
     $ret = array();
     if (is_object($this->result)) {
         while ($row = $this->result->fetch_object()) {
             $ret[] = $row;
         }
     }
     return $ret;
 }
Пример #6
0
 /**
  * Obtenemos un elemento del resultado.
  * @param int $type Tipo de retorno de los valores.
  * @param int|array $cast Cast a aplicar a los elementos.
  * @return mixed
  * @author Ignacio Daniel Rostagno <*****@*****.**>
  */
 public function get_record($type = Database_Query::FETCH_ASSOC, $cast = NULL)
 {
     // $this->next();
     switch ($type) {
         case Database_Query::FETCH_NUM:
             // Obtenemos el arreglo.
             $resultado = $this->query->fetch_array(MYSQLI_NUM);
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_array($resultado)) {
                 return $resultado;
             }
             // Expandimos listado de cast.
             $cast = $this->expand_cast_list($cast, count($resultado));
             // Realizamos el cast.
             $c = count($resultado);
             for ($i = 0; $i < $c; $i++) {
                 $resultado[$i] = $this->cast_field($resultado[$i], $cast[$i]);
             }
             return $resultado;
         case Database_Query::FETCH_OBJ:
             // Obtenemos el objeto.
             $object = $this->query->fetch_object();
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_object($object)) {
                 return $object;
             }
             // Expandimos la lista de cast.
             $cast = $this->expand_cast_list($cast, array_keys(get_object_vars($object)));
             // Realizamos el cast.
             foreach ($cast as $k => $v) {
                 $object->{$k} = $this->cast_field($object->{$k}, $v);
             }
             return $object;
         case Database_Query::FETCH_ASSOC:
         default:
             // Obtenemos el arreglo.
             $resultado = $this->query->fetch_array(MYSQLI_ASSOC);
             // Evitamos cast de consultas erroneas o vacias.
             if (!is_array($resultado)) {
                 return $resultado;
             }
             // Expandimos la lista de cast.
             $cast = $this->expand_cast_list($cast, array_keys($resultado));
             // Realizamos el cast.
             foreach ($cast as $k => $v) {
                 $resultado[$k] = $this->cast_field($resultado[$k], $v);
             }
             return $resultado;
     }
 }
Пример #7
0
 /**
  * Mendapatkan hasil eksekusi query
  *
  * @param   string  $limit  Jumlah pembatasan output
  * @return  mixed
  */
 public function fetch($limit = null)
 {
     if ($limit !== false) {
         $this->doLimit($limit);
     }
     $result = [];
     if ($this->_results) {
         // Lakukan perulangan dari hasil query
         while ($row = $this->_results->fetch_object()) {
             $result[] = $row;
         }
         $this->clear();
     }
     return $result;
 }
Пример #8
0
 public function queryRows($sql)
 {
     $aaData = array();
     if (!$sql) {
         return false;
     }
     if (!$this->real_query($sql)) {
         throw new exception($this->error, $this->errno);
     }
     $result = new mysqli_result($this);
     while ($row = $result->fetch_object()) {
         $aaData[] = $row;
     }
     return $aaData;
 }
Пример #9
0
function display_results(mysqli_result $res)
{
    // Table header:
    echo '<table class="tbl">
	<tr>
		<th>Host</th>
		<th>User</th>
	</tr>
';
    // Fetch and print all the records:
    while ($row = $res->fetch_object()) {
        echo '<tr>
			<td>' . $row->host . '</td>
			<td>' . $row->user . '</td>
		</tr>';
    }
    echo '</table>';
}
 /**
  * @param \mysqli_result $result
  * @param $returnMode
  * @return \Generator
  */
 public function rowGenerator(\mysqli_result $result, $returnMode)
 {
     switch ($returnMode) {
         case self::RETURN_TYPE_ASSOC:
             (yield $result->fetch_assoc());
             break;
         case self::RETURN_TYPE_NUM:
             (yield $result->fetch_array(MYSQLI_NUM));
             break;
         case self::RETURN_TYPE_BOTH:
             (yield $result->fetch_array(MYSQLI_BOTH));
             break;
         case self::RETURN_TYPE_MYSQLI_ROW:
             (yield $result->fetch_row());
             break;
         case self::RETURN_TYPE_OBJ:
             (yield $result->fetch_object());
             break;
         default:
             (yield $result->fetch_assoc());
             break;
     }
 }
Пример #11
0
 /**
  * returns a row as object
  * 
  * @return stdClass
  */
 public function getObj()
 {
     $this->currentRecord = $this->ResultSet->fetch_object();
     return $this->currentRecord;
 }
Пример #12
0
 /**
  * Returns an object of the current row or null if no more rows are in the result
  * @param null $className
  * @param array $params
  * @return object|\stdClass
  */
 public function fetchObject($className = null, array $params = null)
 {
     return $this->dbResult->fetch_object($className, $params);
 }
Пример #13
0
 /**
  * Fetch all rows of a result set as an array of objects
  *
  * If <var>key</var> is not empty then the returned array is indexed by the value of the database key.
  * Returns <var>null</var> if the query fails.
  *
  * @param   mysqli_result  $result The result object. A result set identifier returned by the select() function
  * @param   string         $key    The column name of the index to use
  * @return  array   If <var>key</var> is empty as sequential array of returned rows.
  */
 protected function _fetchObjectList($result, $key = '')
 {
     $array = array();
     while ($row = $result->fetch_object()) {
         if ($key) {
             $array[$row->{$key}] = $row;
         } else {
             $array[] = $row;
         }
     }
     $result->free();
     return $array;
 }
Пример #14
0
 /**
  * returns all results as object
  * @param \mysqli_result $result result of last executed query
  * @return mixed
  */
 public function fetch_object($result)
 {
     return $result->fetch_object();
 }
Пример #15
0
 /**
  * Make log entries
  *
  * @param \mysqli_result $log_res
  * @param string $type
  * @return string $logdata
  * @author Mauri Kujala <*****@*****.**>
  */
 public function make_log_entries($log_res, $type)
 {
     $this_system = "";
     $this_id = "";
     $i = 0;
     while ($obj = $log_res->fetch_object()) {
         if ($this_id != $obj->id) {
             $system_name = $obj->system_name == "" ? $obj->log_system_name : $obj->system_name;
             $log_station_name = $obj->station_name;
             $log_text = $obj->log_entry;
             $date = date_create($obj->stardate);
             $log_added = date_modify($date, "+1286 years");
             $distance = $obj->distance != "" ? number_format($obj->distance, 1) : "";
             if ($this_system != $system_name && $type != "general") {
                 $add = $distance != 0 ? " (distance " . $distance . " ly)" : "";
                 $sortable = "";
                 if ($i == 0 && $type != "log") {
                     $sssort = $this->get_sort("slog");
                     $sortable = '<span class="right">';
                     $sortable .= '<a href="/?slog_sort=' . $sssort . '" title="Sort by date asc/desc">';
                     $sortable .= '<img class="icon" src="/style/img/sort.png" alt="Sort" style="margin-right:0" />';
                     $sortable .= '</a></span>';
                 }
                 /**
                  * provide crosslinks to screenshot gallery, log page, etc
                  */
                 $l_crosslinks = System::crosslinks($system_name, true, false, false);
                 $logdata .= '<header><h2><img class="icon" src="/style/img/system_log.png" alt="log" />';
                 $logdata .= 'System log for <a href="/System?system_name=' . urlencode($system_name) . '">';
                 $logdata .= $system_name;
                 $logdata .= '</a>' . $l_crosslinks . $add . $sortable . '</h2></header>';
                 $logdata .= '<hr>';
             } elseif ($type == "general" && $i == 0) {
                 $gssort = $this->get_sort("glog");
                 $sortable = '<span class="right">';
                 $sortable .= '<a href="/?glog_sort=' . $gssort . '" title="Sort by date asc/desc">';
                 $sortable .= '<img class="icon" src="/style/img/sort.png" alt="Sort" style="margin-right:0" />';
                 $sortable .= '</a></span>';
                 $logdata .= '<header><h2><img class="icon" src="/style/img/log.png" alt="log" />Commander\'s Log' . $sortable . '</h2></header>';
                 $logdata .= '<hr>';
             }
             /**
              * get title icons
              */
             $title_icons = $this->title_icons($obj);
             $log_title = !empty($obj->title) ? '&nbsp;&ndash;&nbsp;' . $obj->title : "";
             $logdata .= '<h3>' . $title_icons;
             $logdata .= '<a href="javascript:void(0)" onclick="toggle_log_edit(\'' . $obj->id . '\')" style="color:inherit" title="Edit entry">';
             $logdata .= date_format($log_added, "j M Y, H:i");
             if (!empty($log_station_name)) {
                 $logdata .= '&nbsp;[Station: ' . htmlspecialchars($log_station_name) . ']';
             }
             $logdata .= $log_title;
             $logdata .= '</a></h3>';
             $logdata .= '<pre class="entriespre" style="margin-bottom:20px">';
             if (!empty($obj->audio)) {
                 $logdata .= $this->get_audio($obj);
             }
             $logdata .= $log_text;
             $logdata .= '</pre>';
         }
         $this_system = $system_name;
         $this_id = $obj->id;
         $i++;
     }
     return $logdata;
 }
Пример #16
0
 /**
  * Returns the next available row as an object
  *  while ($row = $result->object()) { echo $row->id; }
  * @return stdClass
  */
 public function object()
 {
     return $this->result->fetch_object();
 }
Пример #17
0
    /**
     * Display the results
     *
     * @param mysqli_result $main_result
     */
    private function results($main_result)
    {
        $count = $main_result->num_rows;
        if ($count > 0) {
            $last_system = "";
            $ii = 0;
            $tdclass = "";
            while ($obj = $main_result->fetch_object()) {
                $system = $obj->system;
                $system_id = $obj->system_id;
                $sys_population = number_format($obj->population);
                $sys_economy = empty($obj->economy) ? "n/a" : $obj->economy;
                $sys_government = $obj->government;
                $sys_security = empty($obj->security) ? "None" : $obj->security;
                $allegiance = $obj->allegiance;
                $station_name = $obj->station_name;
                /**
                 * provide crosslinks to screenshot gallery, log page, etc
                 */
                $ns_crosslinks = System::crosslinks($system);
                $ss_coordx = $obj->coordx;
                $ss_coordy = $obj->coordy;
                $ss_coordz = $obj->coordz;
                $distance = sqrt(pow($ss_coordx - $this->usex, 2) + pow($ss_coordy - $this->usey, 2) + pow($ss_coordz - $this->usez, 2));
                /**
                 * get allegiance icon for system
                 */
                $pic = get_allegiance_icon($allegiance);
                if ($system != $last_system) {
                    $tdclass = $tdclass == "light" ? "dark" : "light";
                    ?>
                    <tr>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
" style="text-align:center">
                        <img src="/style/img/<?php 
                    echo $pic;
                    ?>
" class="allegiance_icon"
                             alt="<?php 
                    echo $allegiance;
                    ?>
" style="margin:0"/>
                    </td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
">
                        <?php 
                    echo number_format($distance, 2);
                    ?>
 ly<?php 
                    echo $this->is_unknown;
                    ?>
                    </td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
">
                        <a class="send" href="javascript:void(0)" data-send="<?php 
                    echo $system;
                    ?>
"
                           data-id="<?php 
                    echo $system_id;
                    ?>
">
                            <img class="icon" src="/style/img/magic.png" alt="Send"
                                 style="margin-bottom:7px;margin-right:0"
                                 onmouseover="to_view('sysinfo', event)"
                                 onmouseout="$('#sysinfo').fadeToggle('fast')"/>
                        </a>
                        <a href="/System?system_id=<?php 
                    echo $system_id;
                    ?>
">
                            <?php 
                    echo $system;
                    ?>
                        </a>
                        <?php 
                    echo $ns_crosslinks;
                    ?>
                    </td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
"><?php 
                    echo $sys_population;
                    ?>
</td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
"><?php 
                    echo $sys_economy;
                    ?>
</td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
"><?php 
                    echo $sys_government;
                    ?>
</td>
                    <td class="<?php 
                    echo $tdclass;
                    ?>
"><?php 
                    echo $sys_security;
                    ?>
</td>
                    <?php 
                } else {
                    ?>
                    <tr>
                    <td class="transparent" colspan="7" style="height:45px">&nbsp;</td>
                    <?php 
                }
                /**
                 * display station info if necessary
                 */
                if (!empty($station_name)) {
                    $this->station_info($station_name, $obj, $tdclass);
                }
                ?>
                </tr>
                <?php 
                $last_system = $system;
                $ii++;
            }
            // end of while
        } else {
            $colspan = $this->stations !== false ? "10" : "7";
            ?>
            <tr>
                <td class="light" colspan="<?php 
            echo $colspan;
            ?>
">None found!</td>
            </tr>
            <?php 
        }
    }
 private function _parseProductPageAndWriteToDb(mysqli_result $currentProductsResult)
 {
     $selectors = $this->_getSelectorsFromDb(self::SELECTOR_TYPE_PRODUCTS);
     while ($product = $currentProductsResult->fetch_object()) {
         $productDetailsBySelectorName = $this->_getProductDetailsBySelectorName($product->url, $selectors);
         $this->_addProductPriceDetailsToDbLog($productDetailsBySelectorName);
         $this->_checkIfCurrentPriceLowerThanPrevious($productDetailsBySelectorName['product_name'], $product->url);
     }
 }
Пример #19
0
Файл: Result.php Проект: jasny/Q
 /**
  * Returns the values of all rows.
  * CAUTION: resets the result pointer.
  * 
  * {@internal Mind the performance: not ifs in while loop}}
  * 
  * @param  int      $resulttype  A DB_Result::FETCH::% constant
  * @param  boolean  $map         Add mapping for roles   
  * @return array
  */
 function getAll($resulttype = DB::FETCH_ORDERED)
 {
     if ($resulttype == DB::FETCH_VALUE) {
         return $this->getColumn();
     }
     $key_field = $this->getFieldIndex('result:key');
     $rows = array();
     $this->native->data_seek(0);
     $opt = $resulttype & ~0xff;
     if (isset($key_field)) {
         switch ($resulttype & 0xff) {
             case DB::FETCH_ORDERED:
                 while ($row = $this->native->fetch_row()) {
                     $rows[$row[$key_field]] = $row;
                 }
                 break;
             case DB::FETCH_ASSOC:
                 while ($row = $this->native->fetch_assoc()) {
                     $rows[$row['result:key']] = $row;
                 }
                 break;
             case DB::FETCH_FULLARRAY:
                 while ($row = $this->native->fetch_array()) {
                     $rows[$row[$key_field]] = $row;
                 }
                 break;
             case DB::FETCH_OBJECT:
                 while ($row = $this->native->fetch_object()) {
                     $rows[$row->{'result:key'}] = $row;
                 }
                 break;
             default:
                 while ($row = $this->fetchRow($resulttype)) {
                     $rows[] = $row;
                 }
                 if (!empty($rows)) {
                     $rows = array_combine($this->getColumn($key_field), $rows);
                 }
                 break;
         }
     } else {
         switch ($resulttype & 0xff) {
             case DB::FETCH_ORDERED:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_NUM);
                 } else {
                     while ($row = $this->native->fetch_row()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_ASSOC:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_ASSOC);
                 } else {
                     while ($row = $this->native->fetch_assoc()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_OBJECT:
                 while ($row = $this->native->fetch_object()) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_FULLARRAY:
                 if (function_exists('mysqli_fetch_all')) {
                     $rows = $this->native->fetch_all(MYSQLI_BOTH);
                 } else {
                     while ($row = $this->native->fetch_array()) {
                         $rows[] = $row;
                     }
                 }
                 break;
             case DB::FETCH_PERTABLE:
                 while ($row = $this->fetchPerTable($opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_VALUE:
                 while ($row = $this->fetchValue(0, $opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_RECORD:
                 while ($row = $this->fetchRecord($opt)) {
                     $rows[] = $row;
                 }
                 break;
             case DB::FETCH_ROLES:
                 while ($row = $this->fetchRoles($opt)) {
                     $rows[] = $row;
                 }
                 break;
             default:
                 throw new DB_Exception("Unable to fetch all rows: Unknown result type '{$resulttype}'");
         }
     }
     $this->native->data_seek(0);
     return $rows;
 }
Пример #20
0
 /**
  * @param mysqli_result $res
  * @return bool|stdClass
  */
 protected function mysqlFetchObject($res)
 {
     Assert::true($res instanceof mysqli_result, __METHOD__);
     $object = $res->fetch_object();
     if ($object === null) {
         return false;
     }
     return $object;
 }