Пример #1
0
 /**
  * Get result data.
  * @param int The row number from the result that's being retrieved. Row numbers start at 0.
  * @param int The offset of the field being retrieved.
  * @return array|false The contents of one cell from a MySQL result set on success, or false on failure.
  */
 public function query_result($row, $field = 0)
 {
     if (0 == $this->result->num_rows) {
         return false;
     }
     $this->result->data_seek($row);
     $datarow = $this->result->fetch_array();
     return $datarow[$field];
 }
Пример #2
0
 /**
  * Seek the arbitrary pointer in table
  *
  * @param   integer  $offset  The field offset. Must be between zero and the total number of rows minus one
  *
  * @return  boolean
  */
 public function seek($offset)
 {
     if ($this->offsetExists($offset) and $this->_result->data_seek($offset)) {
         // Set the current row to the offset
         $this->_current_row = $this->_internal_row = $offset;
         return TRUE;
     }
     return FALSE;
 }
Пример #3
0
 /**
  * @param mysqli_result $query_id
  * @param int $row
  * @return bool
  */
 public function result($query_id, $row = 0)
 {
     if ($query_id && $query_id->num_rows) {
         $query_id->data_seek($row);
         $result = $query_id->fetch_row();
         return $result[0];
     }
     return false;
 }
Пример #4
0
 /**
  * Moves the cursor to the selected row
  *
  * @param int $num The number of the row to move the cursor to
  * @return static
  * @throws ResultSetException If the row does not exist
  */
 public function toRow($num)
 {
     if (!$this->hasRow($num)) {
         throw new ResultSetException('The row does not exist.');
     }
     $this->current_row = $num;
     $this->result->data_seek($num);
     $this->fetched = $this->result->fetch_row();
     return $this;
 }
Пример #5
0
 /**
  * Rewind
  * 
  */
 public function rewind()
 {
     $this->currentComplete = false;
     $this->position = 0;
     if ($this->resource instanceof \mysqli_stmt) {
         //$this->resource->reset();
     } else {
         $this->resource->data_seek(0);
         // works for both mysqli_result & mysqli_stmt
     }
 }
Пример #6
0
 /**
  * Rewind
  */
 public function rewind()
 {
     if ($this->position !== 0) {
         if ($this->isBuffered === false) {
             throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations');
         }
     }
     $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt
     $this->currentComplete = false;
     $this->position = 0;
 }
Пример #7
0
 /**
  * Navigate to a certain row in the result set
  *
  * @param integer $intIndex The row index
  *
  * @throws \OutOfBoundsException If $intIndex is out of bounds
  */
 protected function data_seek($intIndex)
 {
     if ($intIndex < 0) {
         throw new \OutOfBoundsException("Invalid index {$intIndex} (must be >= 0)");
     }
     $intTotal = $this->num_rows();
     if ($intTotal <= 0) {
         return;
         // see #6319
     }
     if ($intIndex >= $intTotal) {
         throw new \OutOfBoundsException("Invalid index {$intIndex} (only {$intTotal} rows in the result set)");
     }
     $this->resResult->data_seek($intIndex);
 }
Пример #8
0
 public function fetchLastRow()
 {
     $this->result->data_seek($this->getNumRows() - 1);
     return $this->result->fetch_row();
 }
Пример #9
0
 /**
  * @param \mysqli_result $result
  * @return mixed
  */
 public function rewind($result)
 {
     return $result->num_rows > 0 ? $result->data_seek(0) : false;
 }
Пример #10
0
 /**
  * Returns the contents of one cell from a MySQL result set
  *
  * @param    mysqli_result $recordSet The recordset to operate on
  * @param    int           $row       row to get data from
  * @param    mixed         $field     field to return
  * @return   mixed (depends on field content)
  */
 public function dbResult($recordSet, $row, $field = 0)
 {
     if ($this->_verbose) {
         $this->_errorlog("\n*** Inside database->dbResult ***");
         if (empty($recordSet)) {
             $this->_errorlog("\n*** Passed recordset isn't valid ***");
         } else {
             $this->_errorlog("\n*** Everything looks good ***");
         }
         $this->_errorlog("\n*** Leaving database->dbResult ***");
     }
     $retval = '';
     if ($recordSet->data_seek($row)) {
         if (is_numeric($field)) {
             $field = intval($field, 10);
             $row = $recordSet->fetch_row();
         } else {
             $row = $recordSet->fetch_assoc();
         }
         if ($row !== null && isset($row[$field])) {
             $retval = $row[$field];
         }
     }
     return $retval;
 }
<?php

require_once "connect.inc";
$tmp = NULL;
$link = NULL;
require 'table.inc';
if (!($mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket))) {
    printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
$res = new mysqli_result($mysqli);
if (NULL !== ($tmp = @$res->data_seek(0))) {
    printf("[002] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (!($res = $mysqli->query('SELECT * FROM test ORDER BY id LIMIT 4', MYSQLI_STORE_RESULT))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (NULL !== ($tmp = @$res->data_seek())) {
    printf("[004] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (NULL !== ($tmp = @$res->data_seek($link))) {
    printf("[005] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (NULL !== ($tmp = @$res->data_seek($link, $link))) {
    printf("[006] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
}
if (true !== ($tmp = $res->data_seek(3))) {
    printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
}
$row = $res->fetch_assoc();
if (4 != $row['id']) {
    printf("[008] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']);
 public function seek($row)
 {
     if (is_object($this->handle)) {
         return $this->handle->data_seek($row);
     }
 }
Пример #13
0
 /**
  * @param mysqli_result $result
  * @param int $offset
  * @return mixed
  */
 public function data_seek($result, $offset)
 {
     return $result->data_seek($offset);
 }
Пример #14
0
 /**
  * @param mysqli_result|ResultWrapper $res
  * @param int $row
  * @return bool
  */
 protected function mysqlDataSeek($res, $row)
 {
     return $res->data_seek($row);
 }
Пример #15
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;
 }
Пример #16
0
 /**
  * Move internal result pointer.
  *
  * @param mysqli_result $query
  *   The result resource that is being evaluated. This result comes from a call to mysql_query().
  * @param int $row
  *   The desired row number of the new result pointer.
  * @return bool
  *   Returns TRUE on success or FALSE on failure.
  */
 function data_seek($query, $row = 0)
 {
     if ($query instanceof mysqli_result) {
         return $query->data_seek($row);
     }
     return FALSE;
 }
Пример #17
0
 /**
  * @see \Iterator::rewind()
  */
 public function rewind()
 {
     $this->_pointer = 0;
     $this->_result->data_seek(0);
 }
Пример #18
0
 /**
  * Used by implements iterator
  * @return void
  */
 public function rewind()
 {
     $this->result->data_seek(0);
     $this->index = 0;
 }
Пример #19
0
 /**
  * Obtenemos el elemento actual, el tipo de valor devuelto depende del formato especificado.
  * Su implementación es para utilizar la interface iterator.
  * @return mixed
  * @author Ignacio Daniel Rostagno <*****@*****.**>
  */
 public function current()
 {
     $this->query->data_seek($this->position);
     return $this->get_record($this->fetch_type, $this->cast);
 }
Пример #20
0
 /**
  * Set the internal pointer to the given position (must be between 0..getNumRow()-1)
  * @param int $position
  * @return bool
  */
 public function setCurrentRow($position)
 {
     return $this->dbResult->data_seek($position);
 }
Пример #21
0
 public function rewind()
 {
     $this->row = 0;
     $this->res->data_seek(0);
 }