ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
MDB2_Result_Common Class Reference
+ Inheritance diagram for MDB2_Result_Common:
+ Collaboration diagram for MDB2_Result_Common:

Public Member Functions

 __construct (&$db, &$result, $limit=0, $offset=0)
 Constructor. More...
 
 MDB2_Result_Common (&$db, &$result, $limit=0, $offset=0)
 PHP 4 Constructor. More...
 
 setResultTypes ($types)
 Define the list of types to be associated with the columns of a given result set. More...
 
 seek ($rownum=0)
 Seek to a specific row in a result set. More...
 
fetchRow ($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
 Fetch and return a row of data. More...
 
 fetchOne ($colnum=0, $rownum=null)
 fetch single column from the next row from a result set More...
 
 fetchCol ($colnum=0)
 Fetch and return a column from the current row pointer position. More...
 
 fetchAll ($fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
 Fetch and return all rows from the current row pointer position. More...
 
 rowCount ()
 Returns the actual row number that was last fetched (count from 0) More...
 
 numRows ()
 Returns the number of rows in a result object. More...
 
 nextResult ()
 Move the internal result pointer to the next available result. More...
 
 getColumnNames ($flip=false)
 Retrieve the names of columns returned by the DBMS in a query result or from the cache. More...
 
 _getColumnNames ()
 Retrieve the names of columns returned by the DBMS in a query result. More...
 
 numCols ()
 Count the number of columns returned by the DBMS in a query result. More...
 
 getResource ()
 return the resource associated with the result object More...
 
 bindColumn ($column, &$value, $type=null)
 Set bind variable to a column. More...
 
 _assignBindColumns ($row)
 Bind a variable to a value in the result row. More...
 
 free ()
 Free the internal resources associated with result. More...
 

Data Fields

 $db
 
 $result
 
 $rownum = -1
 
 $types = array()
 
 $values = array()
 
 $offset
 
 $offset_count = 0
 
 $limit
 
 $column_names
 

Detailed Description

Definition at line 3343 of file MDB2.php.

Constructor & Destructor Documentation

◆ __construct()

MDB2_Result_Common::__construct ( $db,
$result,
  $limit = 0,
  $offset = 0 
)

Constructor.

Definition at line 3363 of file MDB2.php.

3364 {
3365 $this->db =& $db;
3366 $this->result =& $result;
3367 $this->offset = $offset;
3368 $this->limit = max(0, $limit - 1);
3369 }

References $db, $limit, $offset, and $result.

Referenced by MDB2_Result_Common().

+ Here is the caller graph for this function:

Member Function Documentation

◆ _assignBindColumns()

MDB2_Result_Common::_assignBindColumns (   $row)

Bind a variable to a value in the result row.

Parameters
arrayrow data
Returns
mixed MDB2_OK on success, a MDB2 error on failure

@access private

Definition at line 3786 of file MDB2.php.

3787 {
3788 $row = array_values($row);
3789 foreach ($row as $column => $value) {
3790 if (array_key_exists($column, $this->values)) {
3791 $this->values[$column] = $value;
3792 }
3793 }
3794 return MDB2_OK;
3795 }
const MDB2_OK
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:67

References $row, and MDB2_OK.

Referenced by MDB2_Result_mysql\fetchRow(), MDB2_Result_mysqli\fetchRow(), MDB2_Result_oci8\fetchRow(), MDB2_BufferedResult_oci8\fetchRow(), and MDB2_Result_pgsql\fetchRow().

+ Here is the caller graph for this function:

◆ _getColumnNames()

MDB2_Result_Common::_getColumnNames ( )

Retrieve the names of columns returned by the DBMS in a query result.

Returns
mixed Array variable that holds the names of columns as keys or an MDB2 error on failure. Some DBMS may not return any columns when the result set does not contain any rows.

@access private

Reimplemented in MDB2_Result_mysql, MDB2_Result_mysqli, MDB2_Result_oci8, and MDB2_Result_pgsql.

Definition at line 3702 of file MDB2.php.

3703 {
3704 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3705 'method not implemented', __FUNCTION__);
3706 }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:73

References MDB2_ERROR_UNSUPPORTED.

◆ bindColumn()

MDB2_Result_Common::bindColumn (   $column,
$value,
  $type = null 
)

Set bind variable to a column.

Parameters
intcolumn number or name
mixedvariable reference
stringspecifies the type of the field
Returns
mixed MDB2_OK on success, a MDB2 error on failure

@access public

Definition at line 3754 of file MDB2.php.

3755 {
3756 if (!is_numeric($column)) {
3757 $column_names = $this->getColumnNames();
3758 if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
3759 if ($this->db->options['field_case'] == CASE_LOWER) {
3760 $column = strtolower($column);
3761 } else {
3762 $column = strtoupper($column);
3763 }
3764 }
3765 $column = $column_names[$column];
3766 }
3767 $this->values[$column] =& $value;
3768 if (!is_null($type)) {
3769 $this->types[$column] = $type;
3770 }
3771 return MDB2_OK;
3772 }
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
Definition: MDB2.php:158
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
Definition: MDB2.php:3674

References MDB2_OK, and MDB2_PORTABILITY_FIX_CASE.

◆ fetchAll()

MDB2_Result_Common::fetchAll (   $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rekey = false,
  $force_array = false,
  $group = false 
)

Fetch and return all rows from the current row pointer position.

Parameters
int$fetchmodethe fetch mode to use:
  • MDB2_FETCHMODE_ORDERED
  • MDB2_FETCHMODE_ASSOC
  • MDB2_FETCHMODE_ORDERED | MDB2_FETCHMODE_FLIPPED
  • MDB2_FETCHMODE_ASSOC | MDB2_FETCHMODE_FLIPPED
boolif set to true, the $all will have the first column as its first dimension
boolused only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
boolif true, the values of the returned array is wrapped in another array. If the same key value (in the first column) repeats itself, the values will be appended to this array instead of overwriting the existing values.
Returns
mixed data array on success, a MDB2 error on failure

@access public

See also
getAssoc()

Definition at line 3550 of file MDB2.php.

3552 {
3553 $all = array();
3554 $row = $this->fetchRow($fetchmode);
3555 if (PEAR::isError($row)) {
3556 return $row;
3557 } elseif (!$row) {
3558 return $all;
3559 }
3560
3561 $shift_array = $rekey ? false : null;
3562 if (!is_null($shift_array)) {
3563 if (is_object($row)) {
3564 $colnum = count(get_object_vars($row));
3565 } else {
3566 $colnum = count($row);
3567 }
3568 if ($colnum < 2) {
3569 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3570 'rekey feature requires atleast 2 column', __FUNCTION__);
3571 }
3572 $shift_array = (!$force_array && $colnum == 2);
3573 }
3574
3575 if ($rekey) {
3576 do {
3577 if (is_object($row)) {
3578 $arr = get_object_vars($row);
3579 $key = reset($arr);
3580 unset($row->{$key});
3581 } else {
3582 if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
3583 $key = reset($row);
3584 unset($row[key($row)]);
3585 } else {
3586 $key = array_shift($row);
3587 }
3588 if ($shift_array) {
3589 $row = array_shift($row);
3590 }
3591 }
3592 if ($group) {
3593 $all[$key][] = $row;
3594 } else {
3595 $all[$key] = $row;
3596 }
3597 } while (($row = $this->fetchRow($fetchmode)));
3598 } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
3599 do {
3600 foreach ($row as $key => $val) {
3601 $all[$key][] = $val;
3602 }
3603 } while (($row = $this->fetchRow($fetchmode)));
3604 } else {
3605 do {
3606 $all[] = $row;
3607 } while (($row = $this->fetchRow($fetchmode)));
3608 }
3609
3610 return $all;
3611 }
const MDB2_FETCHMODE_FLIPPED
For multi-dimensional results: normally the first level of arrays is the row number,...
Definition: MDB2.php:142
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:77
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:129
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3458
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279

References $row, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, and MDB2_FETCHMODE_ASSOC.

+ Here is the call graph for this function:

◆ fetchCol()

MDB2_Result_Common::fetchCol (   $colnum = 0)

Fetch and return a column from the current row pointer position.

Parameters
intthe column number to fetch
Returns
mixed data array on success, a MDB2 error on failure

@access public

Definition at line 3504 of file MDB2.php.

3505 {
3506 $column = array();
3507 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3508 $row = $this->fetchRow($fetchmode);
3509 if (is_array($row)) {
3510 if (!array_key_exists($colnum, $row)) {
3511 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3512 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3513 }
3514 do {
3515 $column[] = $row[$colnum];
3516 } while (is_array($row = $this->fetchRow($fetchmode)));
3517 }
3518 if (PEAR::isError($row)) {
3519 return $row;
3520 }
3521 return $column;
3522 }
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:124

References $row, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, MDB2_FETCHMODE_ASSOC, and MDB2_FETCHMODE_ORDERED.

+ Here is the call graph for this function:

◆ fetchOne()

MDB2_Result_Common::fetchOne (   $colnum = 0,
  $rownum = null 
)

fetch single column from the next row from a result set

Parameters
intthe column number to fetch
intnumber of the row where the data can be found
Returns
string data on success, a MDB2 error on failure

@access public

Definition at line 3478 of file MDB2.php.

3479 {
3480 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3481 $row = $this->fetchRow($fetchmode, $rownum);
3482 if (!is_array($row) || PEAR::isError($row)) {
3483 return $row;
3484 }
3485 if (!array_key_exists($colnum, $row)) {
3486 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3487 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3488 }
3489 return $row[$colnum];
3490 }

References $row, $rownum, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, MDB2_FETCHMODE_ASSOC, and MDB2_FETCHMODE_ORDERED.

+ Here is the call graph for this function:

◆ fetchRow()

& MDB2_Result_Common::fetchRow (   $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rownum = null 
)

Fetch and return a row of data.

Parameters
inthow the array data should be indexed
intnumber of the row where the data can be found
Returns
int data array on success, a MDB2 error on failure

@access public

Reimplemented in MDB2_Result_mysql, MDB2_Result_mysqli, MDB2_Result_oci8, MDB2_BufferedResult_oci8, and MDB2_Result_pgsql.

Definition at line 3458 of file MDB2.php.

3459 {
3460 $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3461 'method not implemented', __FUNCTION__);
3462 return $err;
3463 }

References MDB2_ERROR_UNSUPPORTED.

Referenced by fetchAll(), fetchCol(), fetchOne(), and seek().

+ Here is the caller graph for this function:

◆ free()

MDB2_Result_Common::free ( )

Free the internal resources associated with result.

Returns
bool true on success, false if result is invalid

@access public

Reimplemented in MDB2_Result_mysql, MDB2_Result_mysqli, MDB2_Result_oci8, MDB2_BufferedResult_oci8, and MDB2_Result_pgsql.

Definition at line 3807 of file MDB2.php.

3808 {
3809 $this->result = false;
3810 return MDB2_OK;
3811 }

References MDB2_OK.

◆ getColumnNames()

MDB2_Result_Common::getColumnNames (   $flip = false)

Retrieve the names of columns returned by the DBMS in a query result or from the cache.

Parameters
boolIf set to true the values are the column names, otherwise the names of the columns are the keys.
Returns
mixed Array variable that holds the names of columns or an MDB2 error on failure. Some DBMS may not return any columns when the result set does not contain any rows.

@access public

Definition at line 3674 of file MDB2.php.

3675 {
3676 if (!isset($this->column_names)) {
3677 $result = $this->_getColumnNames();
3678 if (PEAR::isError($result)) {
3679 return $result;
3680 }
3681 $this->column_names = $result;
3682 }
3683 if ($flip) {
3684 return array_flip($this->column_names);
3685 }
3686 return $this->column_names;
3687 }
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
Definition: MDB2.php:3702

References $result, and PEAR\isError().

Referenced by MDB2_BufferedResult_oci8\fetchRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResource()

MDB2_Result_Common::getResource ( )

return the resource associated with the result object

Returns
resource

@access public

Definition at line 3735 of file MDB2.php.

3736 {
3737 return $this->result;
3738 }

References $result.

◆ MDB2_Result_Common()

MDB2_Result_Common::MDB2_Result_Common ( $db,
$result,
  $limit = 0,
  $offset = 0 
)

PHP 4 Constructor.

Definition at line 3377 of file MDB2.php.

3378 {
3380 }
__construct(&$db, &$result, $limit=0, $offset=0)
Constructor.
Definition: MDB2.php:3363

References $limit, $offset, $result, and __construct().

+ Here is the call graph for this function:

◆ nextResult()

MDB2_Result_Common::nextResult ( )

Move the internal result pointer to the next available result.

Returns
true on success, false if there is no more result set or an error object on failure

@access public

Reimplemented in MDB2_Result_mysqli, MDB2_BufferedResult_mysqli, and MDB2_Result_pgsql.

Definition at line 3652 of file MDB2.php.

3653 {
3654 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3655 'method not implemented', __FUNCTION__);
3656 }

References MDB2_ERROR_UNSUPPORTED.

◆ numCols()

MDB2_Result_Common::numCols ( )

Count the number of columns returned by the DBMS in a query result.

Returns
mixed integer value with the number of columns, a MDB2 error on failure

@access public

Reimplemented in MDB2_Result_mysql, MDB2_Result_mysqli, MDB2_Result_oci8, and MDB2_Result_pgsql.

Definition at line 3719 of file MDB2.php.

3720 {
3721 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3722 'method not implemented', __FUNCTION__);
3723 }

References MDB2_ERROR_UNSUPPORTED.

◆ numRows()

MDB2_Result_Common::numRows ( )

Returns the number of rows in a result object.

Returns
mixed MDB2 Error Object or the number of rows

@access public

Reimplemented in MDB2_BufferedResult_mysql, MDB2_BufferedResult_mysqli, MDB2_BufferedResult_oci8, and MDB2_BufferedResult_pgsql.

Definition at line 3636 of file MDB2.php.

3637 {
3638 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3639 'method not implemented', __FUNCTION__);
3640 }

References MDB2_ERROR_UNSUPPORTED.

◆ rowCount()

MDB2_Result_Common::rowCount ( )

Returns the actual row number that was last fetched (count from 0)

Returns
int

@access public

Definition at line 3621 of file MDB2.php.

3622 {
3623 return $this->rownum + 1;
3624 }

◆ seek()

MDB2_Result_Common::seek (   $rownum = 0)

Seek to a specific row in a result set.

Parameters
intnumber of the row where the data can be found
Returns
mixed MDB2_OK on success, a MDB2 error on failure

@access public

Reimplemented in MDB2_BufferedResult_mysql, MDB2_BufferedResult_mysqli, MDB2_BufferedResult_oci8, and MDB2_BufferedResult_pgsql.

Definition at line 3432 of file MDB2.php.

3433 {
3434 $target_rownum = $rownum - 1;
3435 if ($this->rownum > $target_rownum) {
3436 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3437 'seeking to previous rows not implemented', __FUNCTION__);
3438 }
3439 while ($this->rownum < $target_rownum) {
3440 $this->fetchRow();
3441 }
3442 return MDB2_OK;
3443 }

References $rownum, fetchRow(), MDB2_ERROR_UNSUPPORTED, and MDB2_OK.

Referenced by MDB2_Result_mysql\fetchRow(), MDB2_Result_mysqli\fetchRow(), MDB2_Result_oci8\fetchRow(), and MDB2_Result_pgsql\fetchRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setResultTypes()

MDB2_Result_Common::setResultTypes (   $types)

Define the list of types to be associated with the columns of a given result set.

This function may be called before invoking fetchRow(), fetchOne(), fetchCol() and fetchAll() so that the necessary data type conversions are performed on the data to be retrieved by them. If this function is not called, the type of all result set columns is assumed to be text, thus leading to not perform any conversions.

Parameters
arrayvariable that lists the data types to be expected in the result set columns. If this array contains less types than the number of columns that are returned in the result set, the remaining columns are assumed to be of the type text. Currently, the types clob and blob are not fully supported.
Returns
mixed MDB2_OK on success, a MDB2 error on failure

@access public

Definition at line 3406 of file MDB2.php.

3407 {
3408 $load = $this->db->loadModule('Datatype', null, true);
3409 if (PEAR::isError($load)) {
3410 return $load;
3411 }
3412 $types = $this->db->datatype->checkResultTypes($types);
3413 if (PEAR::isError($types)) {
3414 return $types;
3415 }
3416 $this->types = $types;
3417 return MDB2_OK;
3418 }

References $types, PEAR\isError(), and MDB2_OK.

+ Here is the call graph for this function:

Field Documentation

◆ $column_names

MDB2_Result_Common::$column_names

Definition at line 3355 of file MDB2.php.

Referenced by MDB2_BufferedResult_oci8\fetchRow().

◆ $db

MDB2_Result_Common::$db

Definition at line 3347 of file MDB2.php.

Referenced by __construct().

◆ $limit

MDB2_Result_Common::$limit

Definition at line 3354 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $offset

MDB2_Result_Common::$offset

Definition at line 3352 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $offset_count

MDB2_Result_Common::$offset_count = 0

Definition at line 3353 of file MDB2.php.

◆ $result

MDB2_Result_Common::$result

Definition at line 3348 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $rownum

◆ $types

MDB2_Result_Common::$types = array()

Definition at line 3350 of file MDB2.php.

Referenced by setResultTypes().

◆ $values

MDB2_Result_Common::$values = array()

Definition at line 3351 of file MDB2.php.


The documentation for this class was generated from the following file: