> For the complete documentation index, see [llms.txt](https://learnsql.gitbook.io/lernmysql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnsql.gitbook.io/lernmysql/dua-con-tro-den-vi-tri-dau-tien-va-sau-do-lai-fetch-tiep-ok.md).

# Đưa con trỏ đến vị trí đầu tiên và sau đó lai fetch tiếp (ok)

![](/files/OmjZLDFKvPFKBNmDZuZu)

![](/files/RPTVp3vRO1P3eM8jmmxG)

{% file src="/files/ixFAplrEBy4agqr7JbDR" %}

C:\xampp\htdocs\namespace\import\db\mysql\query.php

```
<?php
/**
 * Location db\mysql\query.php
 */
namespace DB\Mysql;
use DB\Mysql as mysql;
class Query extends mysql {
  private $resource_id;
  private $record_set;
  function __construct($sql) {
    global $DB_SETTINGS;
    $this->record_set  = Array();
    $this->resource_id = parent::__construct($DB_SETTINGS);
    $this->query($sql);
  }
  public function query($sql) {
    $this->resource_id = mysqli_query($this->connection, $sql);
    if (!$this->resource_id) {
      echo (mysql_error());
      return null;
    }
    return $this;
  }
  public function fetch() {
    $record_set = Array();
    while ($row = mysqli_fetch_assoc($this->resource_id)) {
      $record_set[] = $row;
    }
    return $record_set;
  }
  /** other utility functions **/
  public function first() {
    mysqli_data_seek($this->resource_id, 0);
    $record_set = Array();
    $row        = mysqli_fetch_assoc($this->resource_id);
    if ($row) {
      $record_set = $row;
    }
    return $record_set;
  }
  public function last() {
    mysqli_data_seek($this->resource_id, 0);
    $record_set = Array();
    while ($row = mysqli_fetch_assoc($this->resource_id)) {
      $record_set = $row;
    }
    return $record_set;
  }
}
?>
```
