ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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...
 
 fetch ($fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 fetchObject ()
 
 fetchAssoc ()
 
 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...
 
 execute ($a_data=null)
 
- Public Member Functions inherited from ilDBStatement
 fetchRow ($fetch_mode)
 
 fetch ($fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 rowCount ()
 
 numRows ()
 
 fetchObject ()
 
 fetchAssoc ()
 
 execute ($a_data=null)
 

Data Fields

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

Detailed Description

Definition at line 3348 of file MDB2.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Definition at line 3368 of file MDB2.php.

3369 {
3370 $this->db = $db;
3371 $this->result = $result;
3372 $this->offset = $offset;
3373 $this->limit = max(0, $limit - 1);
3374 }

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 3806 of file MDB2.php.

3807 {
3808 $row = array_values($row);
3809 foreach ($row as $column => $value) {
3810 if (array_key_exists($column, $this->values)) {
3811 $this->values[$column] = $value;
3812 }
3813 }
3814 return MDB2_OK;
3815 }
$column
Definition: 39dropdown.php:62
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
Definition: MDB2.php:72

References $column, $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 3722 of file MDB2.php.

3723 {
3724 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3725 'method not implemented', __FUNCTION__);
3726 }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

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 3774 of file MDB2.php.

3775 {
3776 if (!is_numeric($column)) {
3777 $column_names = $this->getColumnNames();
3778 if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
3779 if ($this->db->options['field_case'] == CASE_LOWER) {
3780 $column = strtolower($column);
3781 } else {
3782 $column = strtoupper($column);
3783 }
3784 }
3786 }
3787 $this->values[$column] =& $value;
3788 if (!is_null($type)) {
3789 $this->types[$column] = $type;
3790 }
3791 return MDB2_OK;
3792 }
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:163
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
Definition: MDB2.php:3694

References $column, MDB2_OK, and MDB2_PORTABILITY_FIX_CASE.

◆ execute()

MDB2_Result_Common::execute (   $a_data = null)
Parameters
array$a_data
Returns
mixed
Exceptions
ilDatabaseException

Implements ilDBStatement.

Definition at line 3839 of file MDB2.php.

3839 {
3840 $res = $this->result->execute($a_data);
3841 if (MDB2::isError($res)) {
3842 throw new ilDatabaseException("There was an MDB2 error executing the prepared query: ".$this->result->getMessage());
3843 }
3844 return $res;
3845 }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
Class ilDatabaseException.

References $res, and MDB2\isError().

+ Here is the call graph for this function:

◆ fetch()

MDB2_Result_Common::fetch (   $fetch_mode = ilDBConstants::FETCHMODE_ASSOC)
Parameters
int$fetch_mode
Returns
mixed

Implements ilDBStatement.

Definition at line 3377 of file MDB2.php.

3377 {
3378 return $this->fetchRow($fetch_mode);
3379 }
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3478

References fetchRow().

+ Here is the call graph for this function:

◆ 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 3570 of file MDB2.php.

3572 {
3573 $all = array();
3574 $row = $this->fetchRow($fetchmode);
3575 if (PEAR::isError($row)) {
3576 return $row;
3577 } elseif (!$row) {
3578 return $all;
3579 }
3580
3581 $shift_array = $rekey ? false : null;
3582 if (!is_null($shift_array)) {
3583 if (is_object($row)) {
3584 $colnum = count(get_object_vars($row));
3585 } else {
3586 $colnum = count($row);
3587 }
3588 if ($colnum < 2) {
3589 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3590 'rekey feature requires atleast 2 column', __FUNCTION__);
3591 }
3592 $shift_array = (!$force_array && $colnum == 2);
3593 }
3594
3595 if ($rekey) {
3596 do {
3597 if (is_object($row)) {
3598 $arr = get_object_vars($row);
3599 $key = reset($arr);
3600 unset($row->{$key});
3601 } else {
3602 if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
3603 $key = reset($row);
3604 unset($row[key($row)]);
3605 } else {
3606 $key = array_shift($row);
3607 }
3608 if ($shift_array) {
3609 $row = array_shift($row);
3610 }
3611 }
3612 if ($group) {
3613 $all[$key][] = $row;
3614 } else {
3615 $all[$key] = $row;
3616 }
3617 } while (($row = $this->fetchRow($fetchmode)));
3618 } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
3619 do {
3620 foreach ($row as $key => $val) {
3621 $all[$key][] = $val;
3622 }
3623 } while (($row = $this->fetchRow($fetchmode)));
3624 } else {
3625 do {
3626 $all[] = $row;
3627 } while (($row = $this->fetchRow($fetchmode)));
3628 }
3629
3630 return $all;
3631 }
const MDB2_FETCHMODE_FLIPPED
For multi-dimensional results: normally the first level of arrays is the row number,...
Definition: MDB2.php:147
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:82
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280

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

+ Here is the call graph for this function:

◆ fetchAssoc()

MDB2_Result_Common::fetchAssoc ( )
Returns
array

Implements ilDBStatement.

Definition at line 3387 of file MDB2.php.

3387 {
3389 }

References ilDBConstants\FETCHMODE_ASSOC, and fetchRow().

+ 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 3524 of file MDB2.php.

3525 {
3526 $column = array();
3527 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3528 $row = $this->fetchRow($fetchmode);
3529 if (is_array($row)) {
3530 if (!array_key_exists($colnum, $row)) {
3531 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3532 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3533 }
3534 do {
3535 $column[] = $row[$colnum];
3536 } while (is_array($row = $this->fetchRow($fetchmode)));
3537 }
3538 if (PEAR::isError($row)) {
3539 return $row;
3540 }
3541 return $column;
3542 }
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:129

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

+ Here is the call graph for this function:

◆ fetchObject()

MDB2_Result_Common::fetchObject ( )
Returns
stdClass

Implements ilDBStatement.

Definition at line 3382 of file MDB2.php.

3382 {
3384 }

References ilDBConstants\FETCHMODE_OBJECT, and fetchRow().

+ 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 3498 of file MDB2.php.

3499 {
3500 $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3501 $row = $this->fetchRow($fetchmode, $rownum);
3502 if (!is_array($row) || PEAR::isError($row)) {
3503 return $row;
3504 }
3505 if (!array_key_exists($colnum, $row)) {
3506 return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3507 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3508 }
3509 return $row[$colnum];
3510 }

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 3478 of file MDB2.php.

3479 {
3480 $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3481 'method not implemented', __FUNCTION__);
3482 return $err;
3483 }

References MDB2_ERROR_UNSUPPORTED.

Referenced by fetch(), fetchAll(), fetchAssoc(), fetchCol(), fetchObject(), 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 3827 of file MDB2.php.

3828 {
3829 $this->result = false;
3830 return MDB2_OK;
3831 }

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 3694 of file MDB2.php.

3695 {
3696 if (!isset($this->column_names)) {
3697 $result = $this->_getColumnNames();
3698 if (PEAR::isError($result)) {
3699 return $result;
3700 }
3701 $this->column_names = $result;
3702 }
3703 if ($flip) {
3704 return array_flip($this->column_names);
3705 }
3706 return $this->column_names;
3707 }
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
Definition: MDB2.php:3722

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 3755 of file MDB2.php.

3756 {
3757 return $this->result;
3758 }

References $result.

◆ MDB2_Result_Common()

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

PHP 4 Constructor.

Definition at line 3397 of file MDB2.php.

3398 {
3400 }
__construct($db, $result, $limit=0, $offset=0)
Constructor.
Definition: MDB2.php:3368

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 3672 of file MDB2.php.

3673 {
3674 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3675 'method not implemented', __FUNCTION__);
3676 }

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 3739 of file MDB2.php.

3740 {
3741 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3742 'method not implemented', __FUNCTION__);
3743 }

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

Implements ilDBStatement.

Reimplemented in MDB2_BufferedResult_mysql, MDB2_BufferedResult_mysqli, MDB2_BufferedResult_oci8, and MDB2_BufferedResult_pgsql.

Definition at line 3656 of file MDB2.php.

3657 {
3658 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3659 'method not implemented', __FUNCTION__);
3660 }

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

Implements ilDBStatement.

Definition at line 3641 of file MDB2.php.

3642 {
3643 return $this->rownum + 1;
3644 }

◆ 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 3452 of file MDB2.php.

3453 {
3454 $target_rownum = $rownum - 1;
3455 if ($this->rownum > $target_rownum) {
3456 return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3457 'seeking to previous rows not implemented', __FUNCTION__);
3458 }
3459 while ($this->rownum < $target_rownum) {
3460 $this->fetchRow();
3461 }
3462 return MDB2_OK;
3463 }

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 3426 of file MDB2.php.

3427 {
3428 $load = $this->db->loadModule('Datatype', null, true);
3429 if (PEAR::isError($load)) {
3430 return $load;
3431 }
3432 $types = $this->db->datatype->checkResultTypes($types);
3433 if (PEAR::isError($types)) {
3434 return $types;
3435 }
3436 $this->types = $types;
3437 return MDB2_OK;
3438 }

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 3360 of file MDB2.php.

Referenced by MDB2_BufferedResult_oci8\fetchRow().

◆ $db

MDB2_Result_Common::$db

Definition at line 3352 of file MDB2.php.

Referenced by __construct().

◆ $limit

MDB2_Result_Common::$limit

Definition at line 3359 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $offset

MDB2_Result_Common::$offset

Definition at line 3357 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $offset_count

MDB2_Result_Common::$offset_count = 0

Definition at line 3358 of file MDB2.php.

◆ $result

MDB2_Result_Common::$result

Definition at line 3353 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

◆ $rownum

◆ $types

MDB2_Result_Common::$types = array()

Definition at line 3355 of file MDB2.php.

Referenced by setResultTypes().

◆ $values

MDB2_Result_Common::$values = array()

Definition at line 3356 of file MDB2.php.


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