MySQL::RowArray PHP Method

RowArray() public method

Reads the current row and returns contents as an array or returns false on error
public RowArray ( integer $optional_row_number = null, integer $resultType = MYSQLI_BOTH ) : array
$optional_row_number integer (Optional) Use to specify a row
$resultType integer (Optional) The type of array Values can be: MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH
return array Array that corresponds to fetched row or FALSE if no rows
    public function RowArray($optional_row_number = null, $resultType = MYSQLI_BOTH)
    {
        $this->ResetError();
        if (!$this->last_result) {
            $this->SetError("No query results exist", -1);
            return false;
        } elseif ($optional_row_number === null) {
            if ($this->active_row > $this->RowCount()) {
                $this->SetError("Cannot read past the end of the records", -1);
                return false;
            } else {
                $this->active_row++;
            }
        } else {
            if ($optional_row_number >= $this->RowCount()) {
                $this->SetError("Row number is greater than the total number of rows", -1);
                return false;
            } else {
                $this->active_row = $optional_row_number;
                $this->Seek($optional_row_number);
            }
        }
        $row = mysqli_fetch_array($this->last_result, $resultType);
        if (!$row) {
            $this->SetError();
            return false;
        } else {
            return $row;
        }
    }

Usage Example

Example #1
0
 /**
  * returns single expense entry as array
  *
  * @param integer $id ID of entry in table exp
  * @global array $kga kimai-global-array
  * @return array
  * @author sl
  */
 public function get_expense($id)
 {
     $id = MySQL::SQLValue($id, MySQL::SQLVALUE_NUMBER);
     $table = $this->getExpenseTable();
     $projectTable = $this->getProjectTable();
     $customerTable = $this->getCustomerTable();
     $query = "SELECT * FROM {$table}\n\t              LEFT JOIN {$projectTable} USING(projectID)\n\t              LEFT JOIN {$customerTable} USING(customerID)\n\t              WHERE {$table}.expenseID = {$id} LIMIT 1;";
     $this->conn->Query($query);
     return $this->conn->RowArray(0, MYSQLI_ASSOC);
 }
All Usage Examples Of MySQL::RowArray