/**
  * @param mysqli_result $mysqli_result
  * @param bool $single
  * @return array|bool|null
  */
 public function fetch($mysqli_result, $single)
 {
     $this->_('fields', array());
     foreach ($mysqli_result->fetch_fields() as $field) {
         $this->_('fields')[$field->name] = $this->rules[$this->types[$field->type]];
     }
     switch (true) {
         case !$mysqli_result:
             return null;
         case $single && $mysqli_result->num_rows == 0:
             $result = false;
             break;
         case $single:
             $result = $this->cast($mysqli_result->fetch_assoc());
             break;
         case $mysqli_result->num_rows == 0:
             $result = array();
             break;
         default:
             $result = array();
             while ($row = $mysqli_result->fetch_assoc()) {
                 $result[] = $this->cast($row);
             }
     }
     $mysqli_result->free();
     return $result;
 }
 /**
  * @return array|null
  */
 public function fetch()
 {
     if (is_bool($this->result)) {
         return $this->result;
     }
     return $this->result->fetch_assoc();
 }
Beispiel #3
0
 public function fetch_accoc()
 {
     while ($row = $this->resource_id->fetch_assoc()) {
         $this->result_array[] = $row;
     }
     return $this->result_array;
 }
 public function nextRecord()
 {
     if (is_object($this->handle) && ($data = $this->handle->fetch_assoc())) {
         return $data;
     } else {
         return false;
     }
 }
Beispiel #5
0
 function fetchAll()
 {
     $data = array();
     while ($record = $this->result->fetch_assoc()) {
         $data[] = $record;
     }
     return $data;
 }
 /**
  * @param Entity $entity
  * @return EntityManagerMysqli
  */
 protected function fetch(\mysqli_result $result, Entity $entity = null)
 {
     while ($data = $result->fetch_assoc()) {
         $this->add($entity->getClone()->serialize($data));
     }
     return $this;
 }
Beispiel #7
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();
 }
 /**
  * Load from mysqli result
  *
  * @return bool
  */
 protected function loadFromMysqliResult()
 {
     $this->currentData = null;
     if (($data = $this->resource->fetch_assoc()) === null) {
         return false;
     }
     $this->position++;
     $this->currentData = $data;
     $this->currentComplete = true;
     $this->nextComplete = true;
     $this->position++;
     return true;
 }
Beispiel #9
0
function loadDefaultData($totalCount, mysqli_result $result)
{
    if ($totalCount == 0) {
        echo "暂无资讯";
        return;
    } else {
        if ($totalCount > 0) {
            $cnt = 0;
            while ($row = $result->fetch_assoc()) {
                if ($cnt < DEFAULT_SHOW) {
                    $list_id = $row["info_id"];
                    echo "<div class=\"list\">";
                    echo "<a href=\"" . $row["origin_link"] . "\" class=\"nav_list\" data-id={$list_id} onclick=\"count({$list_id})\">";
                    echo "<p class=\"caption\">";
                    echo $row["caption"];
                    echo "</p>";
                    echo "<p class=\"subhead\">";
                    echo $row["subhead"];
                    echo "</p>";
                    echo "<div class=\"footer\">";
                    echo "<span class=\"text_des\">";
                    echo $row["origin"];
                    echo "</span>";
                    echo "&nbsp";
                    echo "&nbsp";
                    echo "<span class=\"num_des\">";
                    echo substr($row["publish_date"], 5, 5);
                    echo "</span>";
                    echo "&nbsp";
                    echo "&nbsp";
                    echo "<div class=\"like\">";
                    echo "<img src=\"../images/grayheart.png\" class=\"icon\">";
                    echo "<span class=\"info_like\">";
                    echo showFavNum($row["fav"]);
                    echo "</span>";
                    echo "</div>";
                    echo "</div>";
                    echo "<img src=\"" . $row["pic_link"] . "\" class=\"show_pic\">";
                    echo "</a>";
                    echo "</div>";
                    echo "<hr/>";
                    $cnt++;
                } else {
                    break;
                    return;
                }
            }
        }
    }
}
 /**
  * @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;
     }
 }
Beispiel #11
0
function loadDefaultData($totalCount, mysqli_result $result)
{
    if ($totalCount == 0) {
        return;
    } else {
        if ($totalCount > 0) {
            $cnt = 0;
            while ($row = $result->fetch_assoc()) {
                if ($cnt < DEFAULT_SHOW) {
                    $list_id = $row["info_id"];
                    echo "<div class=\"list\">";
                    echo "<a href=\"" . $row["origin_link"] . "\" class=\"e_wine_list\" data-id={$list_id} onclick=\"count({$list_id})\">";
                    echo "<p class=\"wine_caption\">";
                    echo $row["caption"];
                    echo "</p>";
                    echo "<p class='wine_subhead'>";
                    echo $row['subhead'];
                    echo "</p>";
                    echo "<div class=\"wine_footer\">";
                    echo "<span class=\"wine_orgin\">";
                    echo $row["origin"];
                    echo "</span>";
                    echo "&nbsp";
                    echo "&nbsp";
                    echo "<span class=\"wine_price\">";
                    echo $row["publish_date"];
                    echo "</span>";
                    echo "&nbsp";
                    echo "&nbsp";
                    echo "<div class=\"wine_fav\">";
                    echo "<img src=\"../images/grayheart.png\" class=\"icon\">";
                    echo "<span class=\"wine_fav_num\">";
                    echo showFavNum($row["fav"]);
                    echo "</span>";
                    echo "</div>";
                    echo "</div>";
                    echo "<img src=\"" . $row["pic_link"] . "\" class=\"wine_show_pic\">";
                    echo "</a>";
                    echo "</div>";
                    echo "<hr/>";
                    $cnt++;
                } else {
                    break;
                    return;
                }
            }
        }
    }
}
Beispiel #12
0
function loadMore($page, mysqli_result $result)
{
    $pos = 0;
    $cnt = 0;
    $arry = array();
    while ($row = $result->fetch_assoc()) {
        if ($pos != $page * DEFAULT_SHOW) {
            $pos++;
            continue;
        } else {
            if ($cnt < DEFAULT_SHOW) {
                array_push($arry, $row);
                $cnt++;
            } else {
                break;
                return;
            }
        }
    }
    return json_encode($arry, JSON_UNESCAPED_UNICODE);
}
Beispiel #13
0
 /**
  * @inheritdoc
  */
 public function one()
 {
     return $this->result->fetch_assoc();
 }
Beispiel #14
0
 /**
  * @param mysqli_result $query_id
  * @return array|bool
  */
 public function fetch_assoc($query_id)
 {
     return $query_id ? $query_id->fetch_assoc() : false;
 }
Beispiel #15
0
function loadDefaultComments($totalCount, mysqli_result $res)
{
    if ($totalCount == 0) {
        return;
    } else {
        $cnt = 0;
        while ($row = $res->fetch_assoc()) {
            if ($cnt < DEFAULT_SHOW) {
                echo "<div class=\"conts\">";
                echo "<div class=\"user_bar\">";
                echo "<div class=\"user_info\">";
                echo "<img src=\"" . $row["head_pic"] . "\">";
                echo "<p class=\"uname\">";
                echo $row["nickname"];
                echo "</p>";
                echo "<p class=\"date_time\">";
                echo $row["create_time"];
                echo "</p>";
                echo "</div>";
                echo "</div>";
                echo "<div class=\"comment_info\">";
                echo "<p class=\"comment_cont\">";
                echo $row["comment_cont"];
                echo "</p>";
                echo "</div>";
                echo "</div>";
                echo "<hr/>";
                $cnt++;
            } else {
                break;
                return;
            }
        }
    }
}
Beispiel #16
0
 /**
  * Ziskat radek z dotazu
  * @param mysqli_result $result
  * @return array|bool
  */
 public static function row(mysqli_result $result)
 {
     $row = $result->fetch_assoc();
     if (null !== $row) {
         return $row;
     } else {
         return false;
     }
 }
Beispiel #17
0
 protected function doFetch()
 {
     return is_null($a = $this->result->fetch_assoc()) ? false : $a;
 }
Beispiel #18
0
 /**
  * @param \mysqli_result $result
  * @return array
  */
 public function fetchAssoc($result)
 {
     if (!$result) {
         return $result;
     }
     return $result->fetch_assoc();
 }
Beispiel #19
0
 /**
  * Returns next result row or false.
  *
  * @return array|false
  */
 protected function fetchRowInternal()
 {
     return $this->resource->fetch_assoc();
 }
Beispiel #20
0
 /**
  * Package query results into models.
  *
  * @method packageResults
  *
  * @param Result $result The results to package
  * @param Query  $query  The query which produced the results
  *
  * @return Collection The results
  */
 private function packageResults(Result $result, $query)
 {
     // Create an empty collection to store results in
     $collection = new Collection();
     $collection->totalRows = $this->foundRows();
     // Loop through the query results
     while (($data = $result->fetch_assoc()) !== null) {
         // Prepare the row data for storage within a model
         $prepared = $this->prepareData($data);
         // Package the row into a model
         $this->packageModel($prepared, $collection, $query);
     }
     return $collection;
 }
Beispiel #21
0
 public function __construct(mysqli_result $rs)
 {
     while ($row = $rs->fetch_assoc()) {
         $this->a[] = $row;
     }
 }
Beispiel #22
0
function pm_process_result(mysqli_result $result, $message_count)
{
    $message_array = array();
    while (($pm_data = $result->fetch_assoc()) !== null) {
        if (!isset($pm_data['FROM_LOGON'])) {
            $pm_data['FROM_LOGON'] = gettext("Unknown user");
        }
        if (!isset($pm_data['FROM_NICKNAME'])) {
            $pm_data['FROM_NICKNAME'] = "";
        }
        $message_array[$pm_data['MID']] = array('CREATED' => $pm_data['CREATED'], 'FROM_UID' => $pm_data['FROM_UID'], 'FROM_LOGON' => $pm_data['FROM_LOGON'], 'FROM_NICKNAME' => $pm_data['FROM_NICKNAME'], 'MID' => $pm_data['MID'], 'RECIPIENTS' => array(), 'REPLY_TO_MID' => $pm_data['REPLY_TO_MID'], 'SUBJECT' => $pm_data['SUBJECT'], 'TYPE' => $pm_data['TYPE']);
    }
    pms_get_recipients($message_array);
    pms_have_attachments($message_array);
    return array('message_count' => $message_count, 'message_array' => $message_array);
}
 /**
  * @param mysqli_result $result
  * @return mixed
  */
 public function fetch_assoc($result)
 {
     return $result->fetch_assoc();
 }
Beispiel #24
0
 public function fetch_row()
 {
     return $this->result ? $this->result->fetch_assoc() : null;
 }
Beispiel #25
0
 /**
  * Return associative array of the current row or null if no more rows are in the result
  * @return array|null
  */
 public function fetchAssoc()
 {
     return $this->dbResult->fetch_assoc();
 }
 /**
  * Return reference to next row in result set.
  * @param mysqli_result|resource|PDOStatement $result
  * @return array
  */
 public function nextRow($result)
 {
     return $result->fetch_assoc();
 }
Beispiel #27
0
 public static function fetch(\mysqli_result $result)
 {
     return $result->fetch_assoc();
 }
Beispiel #28
0
 /**
  * Get all records as an array of associative arrays
  * @param mysqli_result $result
  * @return array empty array if no result
  */
 public function getAssocArrays(mysqli_result $result = null)
 {
     $contentArray = array();
     if ($result != null) {
         while ($row = $result->fetch_assoc()) {
             $contentArray[] = $row;
         }
     }
     return $contentArray;
 }
Beispiel #29
0
 /**
  * Get all rows from the DB result.
  *
  * @param \mysqli_result|bool $result The return of query method.
  *
  * @return array The array of SQL rows
  */
 public function getRowsArray($result)
 {
     $rows = [];
     if (!$result) {
         return $rows;
     }
     while ($row = $result->fetch_assoc()) {
         $rows[] = $row;
     }
     $result->free();
     return $rows;
 }
Beispiel #30
0
 /**
  * Возвращает строку в виде ассоциативного массива из результата последнего запроса к БД
  *
  * @param \mysqli_result $result альтеранативный результат
  * @return array
  */
 public function fetchRow($result = null)
 {
     if ($result) {
         return $result->fetch_assoc();
     } else {
         if ($this->result) {
             return $this->result->fetch_assoc();
         } else {
             return null;
         }
     }
 }