ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 

Data Fields

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

Detailed Description

Definition at line 3354 of file MDB2.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Definition at line 3374 of file MDB2.php.

References $result.

3375  {
3376  $this->db = $db;
3377  $this->result = $result;
3378  $this->offset = $offset;
3379  $this->limit = max(0, $limit - 1);
3380  }

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

private

Definition at line 3812 of file MDB2.php.

References $column, $row, and MDB2_OK.

3813  {
3814  $row = array_values($row);
3815  foreach ($row as $column => $value) {
3816  if (array_key_exists($column, $this->values)) {
3817  $this->values[$column] = $value;
3818  }
3819  }
3820  return MDB2_OK;
3821  }
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
$column
Definition: 39dropdown.php:62

◆ _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.

private

Definition at line 3728 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

3729  {
3730  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3731  'method not implemented', __FUNCTION__);
3732  }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ 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

public

Definition at line 3780 of file MDB2.php.

References $column, $type, MDB2_OK, and MDB2_PORTABILITY_FIX_CASE.

3781  {
3782  if (!is_numeric($column)) {
3783  $column_names = $this->getColumnNames();
3784  if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
3785  if ($this->db->options['field_case'] == CASE_LOWER) {
3786  $column = strtolower($column);
3787  } else {
3788  $column = strtoupper($column);
3789  }
3790  }
3792  }
3793  $this->values[$column] =& $value;
3794  if (!is_null($type)) {
3795  $this->types[$column] = $type;
3796  }
3797  return MDB2_OK;
3798  }
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
$type
$column
Definition: 39dropdown.php:62
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
Definition: MDB2.php:3700
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

◆ execute()

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

Implements ilDBStatement.

Definition at line 3845 of file MDB2.php.

References $res, and MDB2\isError().

3845  {
3846  $res = $this->result->execute($a_data);
3847  if (MDB2::isError($res)) {
3848  throw new ilDatabaseException("There was an MDB2 error executing the prepared query: ".$this->result->getMessage());
3849  }
3850  return $res;
3851  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
Class ilDatabaseException.
foreach($_POST as $key=> $value) $res
+ 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 3383 of file MDB2.php.

3383  {
3384  return $this->fetchRow($fetch_mode);
3385  }
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484

◆ 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

public

See also
getAssoc()

Definition at line 3576 of file MDB2.php.

References $key, $row, array, PEAR\isError(), MDB2_ERROR_TRUNCATED, MDB2_FETCHMODE_ASSOC, and MDB2_FETCHMODE_FLIPPED.

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

◆ fetchAssoc()

MDB2_Result_Common::fetchAssoc ( )
Returns
array

Implements ilDBStatement.

Definition at line 3393 of file MDB2.php.

References ilDBConstants\FETCHMODE_ASSOC.

3393  {
3395  }
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484

◆ 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

public

Definition at line 3530 of file MDB2.php.

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

3531  {
3532  $column = array();
3533  $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3534  $row = $this->fetchRow($fetchmode);
3535  if (is_array($row)) {
3536  if (!array_key_exists($colnum, $row)) {
3537  return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3538  'column is not defined in the result set: '.$colnum, __FUNCTION__);
3539  }
3540  do {
3541  $column[] = $row[$colnum];
3542  } while (is_array($row = $this->fetchRow($fetchmode)));
3543  }
3544  if (PEAR::isError($row)) {
3545  return $row;
3546  }
3547  return $column;
3548  }
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:129
$column
Definition: 39dropdown.php:62
Create styles array
The data for the language used.
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:82
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ fetchObject()

MDB2_Result_Common::fetchObject ( )
Returns
stdClass

Implements ilDBStatement.

Definition at line 3388 of file MDB2.php.

References ilDBConstants\FETCHMODE_OBJECT.

3388  {
3390  }
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484

◆ 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

public

Definition at line 3504 of file MDB2.php.

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

3505  {
3506  $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
3507  $row = $this->fetchRow($fetchmode, $rownum);
3508  if (!is_array($row) || PEAR::isError($row)) {
3509  return $row;
3510  }
3511  if (!array_key_exists($colnum, $row)) {
3512  return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
3513  'column is not defined in the result set: '.$colnum, __FUNCTION__);
3514  }
3515  return $row[$colnum];
3516  }
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
Definition: MDB2.php:134
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
Definition: MDB2.php:129
const MDB2_ERROR_TRUNCATED
Definition: MDB2.php:82
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ 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

public

Definition at line 3484 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

3485  {
3486  $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3487  'method not implemented', __FUNCTION__);
3488  return $err;
3489  }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ free()

MDB2_Result_Common::free ( )

Free the internal resources associated with result.

Returns
bool true on success, false if result is invalid

public

Definition at line 3833 of file MDB2.php.

References MDB2_OK.

3834  {
3835  $this->result = false;
3836  return MDB2_OK;
3837  }
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

◆ 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.

public

Definition at line 3700 of file MDB2.php.

References $result, and PEAR\isError().

3701  {
3702  if (!isset($this->column_names)) {
3703  $result = $this->_getColumnNames();
3704  if (PEAR::isError($result)) {
3705  return $result;
3706  }
3707  $this->column_names = $result;
3708  }
3709  if ($flip) {
3710  return array_flip($this->column_names);
3711  }
3712  return $this->column_names;
3713  }
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
Definition: MDB2.php:3728
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getResource()

MDB2_Result_Common::getResource ( )

return the resource associated with the result object

Returns
resource

public

Definition at line 3761 of file MDB2.php.

References $result.

3762  {
3763  return $this->result;
3764  }

◆ MDB2_Result_Common()

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

PHP 4 Constructor.

Definition at line 3403 of file MDB2.php.

3404  {
3405  $this->__construct($db, $result, $limit, $offset);
3406  }
__construct($db, $result, $limit=0, $offset=0)
Constructor.
Definition: MDB2.php:3374

◆ 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

public

Definition at line 3678 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

3679  {
3680  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3681  'method not implemented', __FUNCTION__);
3682  }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ 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

public

Definition at line 3745 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

3746  {
3747  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3748  'method not implemented', __FUNCTION__);
3749  }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ numRows()

MDB2_Result_Common::numRows ( )

Returns the number of rows in a result object.

Returns
mixed MDB2 Error Object or the number of rows

public

Implements ilDBStatement.

Definition at line 3662 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

3663  {
3664  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3665  'method not implemented', __FUNCTION__);
3666  }
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ rowCount()

MDB2_Result_Common::rowCount ( )

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

Returns
int

public

Implements ilDBStatement.

Definition at line 3647 of file MDB2.php.

3648  {
3649  return $this->rownum + 1;
3650  }

◆ 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

public

Definition at line 3458 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED, and MDB2_OK.

3459  {
3460  $target_rownum = $rownum - 1;
3461  if ($this->rownum > $target_rownum) {
3462  return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
3463  'seeking to previous rows not implemented', __FUNCTION__);
3464  }
3465  while ($this->rownum < $target_rownum) {
3466  $this->fetchRow();
3467  }
3468  return MDB2_OK;
3469  }
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
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
Definition: MDB2.php:3484
const MDB2_ERROR_UNSUPPORTED
Definition: MDB2.php:78

◆ 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

public

Definition at line 3432 of file MDB2.php.

References PEAR\isError(), and MDB2_OK.

3433  {
3434  $load = $this->db->loadModule('Datatype', null, true);
3435  if (PEAR::isError($load)) {
3436  return $load;
3437  }
3438  $types = $this->db->datatype->checkResultTypes($types);
3439  if (PEAR::isError($types)) {
3440  return $types;
3441  }
3442  $this->types = $types;
3443  return MDB2_OK;
3444  }
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
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

Field Documentation

◆ $column_names

MDB2_Result_Common::$column_names

Definition at line 3366 of file MDB2.php.

◆ $db

MDB2_Result_Common::$db

Definition at line 3358 of file MDB2.php.

◆ $limit

MDB2_Result_Common::$limit

Definition at line 3365 of file MDB2.php.

◆ $offset

MDB2_Result_Common::$offset

Definition at line 3363 of file MDB2.php.

◆ $offset_count

MDB2_Result_Common::$offset_count = 0

Definition at line 3364 of file MDB2.php.

◆ $result

MDB2_Result_Common::$result

Definition at line 3359 of file MDB2.php.

◆ $rownum

MDB2_Result_Common::$rownum = -1

Definition at line 3360 of file MDB2.php.

◆ $types

MDB2_Result_Common::$types = array()

Definition at line 3361 of file MDB2.php.

◆ $values

MDB2_Result_Common::$values = array()

Definition at line 3362 of file MDB2.php.


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