/**
  * Moves the cursor to the next row
  *
  * @return static $this
  * @throws ResultSetException If the next row does not exist
  */
 public function toNextRow()
 {
     if (!$this->hasNextRow()) {
         throw new ResultSetException('The next row does not exist.');
     }
     if ($this->current_row === null) {
         $this->current_row = 0;
     } else {
         $this->current_row++;
     }
     $this->fetched = $this->result->fetch_row();
     return $this;
 }
 /**
  * @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 #3
0
 /**
  * @param \mysqli_result $result
  * @return array|null
  */
 public function fetchRow($result)
 {
     return $result->fetch_row();
 }
Beispiel #4
0
 /**
  * @param mysqli_result $query_id
  * @return array|bool
  */
 public function fetch_row($query_id)
 {
     return $query_id ? $query_id->fetch_row() : false;
 }
Beispiel #5
0
 public function fetchLastRow()
 {
     $this->result->data_seek($this->getNumRows() - 1);
     return $this->result->fetch_row();
 }
 /**
  * Purpose: Creates an associative array to be used with the HtmlForm
  *   class' methods that populate lists.
  * @param mysqli_result $qryResults The query result record set.  The
  *   result should consist of two columns: the first column will contain
  *   an ID, and second will contain corresponding text.
  * @return array Associative array, where the array index comes from
  *   the qryResults' first column, and the array value comes from the
  *   qryResults' second column.
  */
 public static function createArray($qryResults)
 {
     // Create an empty result array
     $result = array();
     // Loop through all rows in the result set
     while ($row = $qryResults->fetch_row()) {
         // Set an entry in the result set with the index as the first
         // column in the result set, and the value as the second column
         $result[$row[0]] = $row[1];
     }
     // Return the result array
     return $result;
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
0
 public function fetch_row()
 {
     return $this->resource_id->fetch_row();
 }
Beispiel #9
0
 /**
  * Get all fields of all records in one single non-associative array
  * It's basically all values available concatened in a single array
  * @param mysqli_result $result
  * @return array empty array if no result
  */
 public function getRowArrays(mysqli_result $result = null)
 {
     $arrayFromResultSet = array();
     if ($result != null) {
         while ($row = $result->fetch_row()) {
             foreach ($row as $value) {
                 $arrayFromResultSet[] = stripcslashes($value);
             }
         }
     }
     return $arrayFromResultSet;
 }
Beispiel #10
0
 /**
  * Returns the next available row as an enumerated array
  *  while ($row = $result->enum()) { echo $row[0]; }
  * @return array
  */
 public function enum()
 {
     return $this->result->fetch_row();
 }
Beispiel #11
0
 /**
  * Fetch the current row as enumerated array
  *
  * @return array The row as array
  */
 protected function fetch_row()
 {
     return $this->resResult->fetch_row();
 }
Beispiel #12
0
 /**
  * @param $res mysqli_result
  * @return mixed
  */
 public static function result(mysqli_result $res)
 {
     $row = $res->fetch_row();
     return $row[0];
 }
Beispiel #13
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;
 }
Beispiel #14
0
 /**
  * Fetch an array of single field results
  *
  *
  * @param   mysqli_result  	$result The result object. A result set identifier returned by the select() function
  * @param   integer         $key    The index to use
  * @return  array           A sequential array of returned rows.
  */
 protected function _fetchFieldList($result, $key = 0)
 {
     $array = array();
     while ($row = $result->fetch_row()) {
         $array[] = $row[(int) $key];
     }
     $result->free();
     return $array;
 }
Beispiel #15
0
<?php

require_once "connect.inc";
$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
$mysql->real_query("SELECT 'foo' FROM test_062_table_1");
$myresult = new mysqli_result($mysql);
$row = $myresult->fetch_row();
$myresult->close();
$mysql->close();
var_dump($row);
print "done!";
Beispiel #16
0
 /**
  * Return array with indexed keys of the current row or null if no more rows are in the result
  * @return array|null
  */
 public function fetchRow()
 {
     return $this->dbResult->fetch_row();
 }
Beispiel #17
0
 /**
  * Ziskat konkretni radek a sloupec z dotazu
  *
  * @param mysqli_result $result vysledek dotazu
  * @param int           $row    cislo radku
  * @param int           $column cislo sloupce
  */
 public static function result(mysqli_result $result, $row, $column = 0)
 {
     $row = $result->fetch_row();
     if (null !== $row && isset($row[$column])) {
         return $row[$column];
     } else {
         return null;
     }
 }
Beispiel #18
0
 /**
  * 从结果集中取得一行作为数字索引数组
  */
 function fetch_row(mysqli_result $query)
 {
     return $query->fetch_row();
 }
Beispiel #19
0
 /**
  * Fetches a record as numeric array
  * @return array
  */
 public function row()
 {
     return $this->res->fetch_row();
 }