ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
MDB2_Extended Class Reference
+ Inheritance diagram for MDB2_Extended:
+ Collaboration diagram for MDB2_Extended:

Public Member Functions

 autoPrepare ($table, $table_fields, $mode=MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=MDB2_PREPARE_MANIP)
 Generate an insert, update or delete query and call prepare() on it. More...
 
autoExecute ($table, $fields_values, $mode=MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_class=true, $result_types=MDB2_PREPARE_MANIP)
 Generate an insert, update or delete query and call prepare() and execute() on it. More...
 
 buildManipSQL ($table, $table_fields, $mode, $where=false)
 Make automaticaly an sql query for prepare() More...
 
limitQuery ($query, $types, $limit, $offset=0, $result_class=true, $result_wrap_class=false)
 Generates a limited query. More...
 
 execParam ($query, $params=array(), $param_types=null)
 Execute a parameterized DML statement. More...
 
 getOne ($query, $type=null, $params=array(), $param_types=null, $colnum=0)
 Fetch the first column of the first row of data returned from a query. More...
 
 getRow ($query, $types=null, $params=array(), $param_types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT)
 Fetch the first row of data returned from a query. More...
 
 getCol ($query, $type=null, $params=array(), $param_types=null, $colnum=0)
 Fetch a single column from a result set and return it as an indexed array. More...
 
 getAll ($query, $types=null, $params=array(), $param_types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
 Fetch all the rows returned from a query. More...
 
 getAssoc ($query, $types=null, $params=array(), $param_types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $force_array=false, $group=false)
 Fetch the entire result set of a query and return it as an associative array using the first column as the key. More...
 
 executeMultiple (&$stmt, $params=null)
 This function does several execute() calls on the same statement handle. More...
 
 getBeforeID ($table, $field=null, $ondemand=true, $quote=true)
 Returns the next free id of a sequence if the RDBMS does not support auto increment. More...
 
 getAfterID ($id, $table, $field=null)
 Returns the autoincrement ID if supported or $id. More...
 
- Public Member Functions inherited from MDB2_Module_Common
 __construct ($db_index)
 Constructor. More...
 
 MDB2_Module_Common ($db_index)
 PHP 4 Constructor. More...
 
getDBInstance ()
 Get the instance of MDB2 associated with the module instance. More...
 

Additional Inherited Members

- Data Fields inherited from MDB2_Module_Common
 $db_index
 

Detailed Description

Definition at line 68 of file Extended.php.

Member Function Documentation

◆ autoExecute()

& MDB2_Extended::autoExecute (   $table,
  $fields_values,
  $mode = MDB2_AUTOQUERY_INSERT,
  $where = false,
  $types = null,
  $result_class = true,
  $result_types = MDB2_PREPARE_MANIP 
)

Generate an insert, update or delete query and call prepare() and execute() on it.

Parameters
stringname of the table
arrayassoc ($key=>$value) where $key is a field name and $value its value
inttype of query to build MDB2_AUTOQUERY_INSERT MDB2_AUTOQUERY_UPDATE MDB2_AUTOQUERY_DELETE MDB2_AUTOQUERY_SELECT
string(in case of update and delete queries, this string will be put after the sql WHERE statement)
arraythat contains the types of the placeholders
stringwhich specifies which result class to use
mixedarray that contains the types of the columns in the result set or MDB2_PREPARE_RESULT, if set to MDB2_PREPARE_MANIP the query is handled as a manipulation query
Returns
bool|MDB2_Error true on success, a MDB2 error on failure
See also
buildManipSQL
autoPrepare User interface

Definition at line 131 of file Extended.php.

References $params, $query, $result, array, autoPrepare(), buildManipSQL(), MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2_AUTOQUERY_SELECT.

133  {
134  $fields_values = (array)$fields_values;
135  if ($mode == MDB2_AUTOQUERY_SELECT) {
136  if (is_array($result_types)) {
137  $keys = array_keys($result_types);
138  } elseif (!empty($fields_values)) {
139  $keys = $fields_values;
140  } else {
141  $keys = array();
142  }
143  } else {
144  $keys = array_keys($fields_values);
145  }
146  $params = array_values($fields_values);
147  if (empty($params)) {
148  $query = $this->buildManipSQL($table, $keys, $mode, $where);
149 
150  $db =& $this->getDBInstance();
151  if (PEAR::isError($db)) {
152  return $db;
153  }
154  if ($mode == MDB2_AUTOQUERY_SELECT) {
155  $result =& $db->query($query, $result_types, $result_class);
156  } else {
157  $result = $db->exec($query);
158  }
159  } else {
160  $stmt = $this->autoPrepare($table, $keys, $mode, $where, $types, $result_types);
161  if (PEAR::isError($stmt)) {
162  return $stmt;
163  }
164  $result =& $stmt->execute($params, $result_class);
165  $stmt->free();
166  }
167  return $result;
168  }
$result
const MDB2_AUTOQUERY_SELECT
Definition: Extended.php:59
Create styles array
The data for the language used.
buildManipSQL($table, $table_fields, $mode, $where=false)
Make automaticaly an sql query for prepare()
Definition: Extended.php:194
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
autoPrepare($table, $table_fields, $mode=MDB2_AUTOQUERY_INSERT, $where=false, $types=null, $result_types=MDB2_PREPARE_MANIP)
Generate an insert, update or delete query and call prepare() on it.
Definition: Extended.php:92
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ autoPrepare()

MDB2_Extended::autoPrepare (   $table,
  $table_fields,
  $mode = MDB2_AUTOQUERY_INSERT,
  $where = false,
  $types = null,
  $result_types = MDB2_PREPARE_MANIP 
)

Generate an insert, update or delete query and call prepare() on it.

Parameters
stringtable
arraythe fields names
inttype of query to build MDB2_AUTOQUERY_INSERT MDB2_AUTOQUERY_UPDATE MDB2_AUTOQUERY_DELETE MDB2_AUTOQUERY_SELECT
string(in case of update and delete queries, this string will be put after the sql WHERE statement)
arraythat contains the types of the placeholders
mixedarray that contains the types of the columns in the result set or MDB2_PREPARE_RESULT, if set to MDB2_PREPARE_MANIP the query is handled as a manipulation query
Returns
resource handle for the query
See also
buildManipSQL User interface

Definition at line 92 of file Extended.php.

References $query, buildManipSQL(), MDB2_Module_Common\getDBInstance(), and PEAR\isError().

Referenced by autoExecute().

94  {
95  $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
96  if (PEAR::isError($query)) {
97  return $query;
98  }
99  $db =& $this->getDBInstance();
100  if (PEAR::isError($db)) {
101  return $db;
102  }
103  return $db->prepare($query, $types, $result_types);
104  }
buildManipSQL($table, $table_fields, $mode, $where=false)
Make automaticaly an sql query for prepare()
Definition: Extended.php:194
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildManipSQL()

MDB2_Extended::buildManipSQL (   $table,
  $table_fields,
  $mode,
  $where = false 
)

Make automaticaly an sql query for prepare()

Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), MDB2_AUTOQUERY_INSERT) will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?) NB : - This belongs more to a SQL Builder class, but this is a simple facility

  • Be carefull ! If you don't give a $where param with an UPDATE/DELETE query, all the records of the table will be updated/deleted !
Parameters
stringname of the table
orderedarray containing the fields names
inttype of query to build MDB2_AUTOQUERY_INSERT MDB2_AUTOQUERY_UPDATE MDB2_AUTOQUERY_DELETE MDB2_AUTOQUERY_SELECT
string(in case of update and delete queries, this string will be put after the sql WHERE statement)
Returns
string sql query for prepare() public

Definition at line 194 of file Extended.php.

References MDB2_Module_Common\getDBInstance(), PEAR\isError(), MDB2_AUTOQUERY_DELETE, MDB2_AUTOQUERY_INSERT, MDB2_AUTOQUERY_SELECT, MDB2_AUTOQUERY_UPDATE, MDB2_ERROR_NEED_MORE_DATA, and MDB2_ERROR_SYNTAX.

Referenced by autoExecute(), and autoPrepare().

195  {
196  $db =& $this->getDBInstance();
197  if (PEAR::isError($db)) {
198  return $db;
199  }
200 
201  if ($db->options['quote_identifier']) {
202  $table = $db->quoteIdentifier($table);
203  }
204 
205  if (!empty($table_fields) && $db->options['quote_identifier']) {
206  foreach ($table_fields as $key => $field) {
207  $table_fields[$key] = $db->quoteIdentifier($field);
208  }
209  }
210 
211  if ($where !== false && !is_null($where)) {
212  if (is_array($where)) {
213  $where = implode(' AND ', $where);
214  }
215  $where = ' WHERE '.$where;
216  }
217 
218  switch ($mode) {
220  if (empty($table_fields)) {
221  return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
222  'Insert requires table fields', __FUNCTION__);
223  }
224  $cols = implode(', ', $table_fields);
225  $values = '?'.str_repeat(', ?', (count($table_fields) - 1));
226  return 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$values.')';
227  break;
229  if (empty($table_fields)) {
230  return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
231  'Update requires table fields', __FUNCTION__);
232  }
233  $set = implode(' = ?, ', $table_fields).' = ?';
234  $sql = 'UPDATE '.$table.' SET '.$set.$where;
235  return $sql;
236  break;
238  $sql = 'DELETE FROM '.$table.$where;
239  return $sql;
240  break;
242  $cols = !empty($table_fields) ? implode(', ', $table_fields) : '*';
243  $sql = 'SELECT '.$cols.' FROM '.$table.$where;
244  return $sql;
245  break;
246  }
247  return $db->raiseError(MDB2_ERROR_SYNTAX, null, null,
248  'Non existant mode', __FUNCTION__);
249  }
const MDB2_ERROR_SYNTAX
Definition: MDB2.php:74
const MDB2_AUTOQUERY_SELECT
Definition: Extended.php:59
const MDB2_AUTOQUERY_DELETE
Definition: Extended.php:58
const MDB2_ERROR_NEED_MORE_DATA
Definition: MDB2.php:92
const MDB2_AUTOQUERY_UPDATE
Definition: Extended.php:57
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
const MDB2_AUTOQUERY_INSERT
Used by autoPrepare()
Definition: Extended.php:56
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execParam()

MDB2_Extended::execParam (   $query,
  $params = array(),
  $param_types = null 
)

Execute a parameterized DML statement.

Parameters
stringthe SQL query
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
Returns
int|MDB2_Error affected rows on success, a MDB2 error on failure public

Definition at line 297 of file Extended.php.

References $params, $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2_PREPARE_MANIP.

298  {
299  $db =& $this->getDBInstance();
300  if (PEAR::isError($db)) {
301  return $db;
302  }
303 
304  settype($params, 'array');
305  if (empty($params)) {
306  return $db->exec($query);
307  }
308 
309  $stmt = $db->prepare($query, $param_types, MDB2_PREPARE_MANIP);
310  if (PEAR::isError($stmt)) {
311  return $stmt;
312  }
313 
314  $result = $stmt->execute($params);
315  if (PEAR::isError($result)) {
316  return $result;
317  }
318 
319  $stmt->free();
320  return $result;
321  }
$result
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ executeMultiple()

MDB2_Extended::executeMultiple ( $stmt,
  $params = null 
)

This function does several execute() calls on the same statement handle.

$params must be an array indexed numerically from 0, one execute call is done for every 'row' in the array.

If an error occurs during execute(), executeMultiple() does not execute the unfinished rows, but rather returns that error.

Parameters
resourcequery handle from prepare()
arraynumeric array containing the data to insert into the query
Returns
bool|MDB2_Error true on success, a MDB2 error on failure public
See also
prepare(), execute()

Definition at line 641 of file Extended.php.

References $params, $result, PEAR\isError(), and MDB2_OK.

642  {
643  for ($i = 0, $j = count($params); $i < $j; $i++) {
644  $result = $stmt->execute($params[$i]);
645  if (PEAR::isError($result)) {
646  return $result;
647  }
648  }
649  return MDB2_OK;
650  }
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
$result
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getAfterID()

MDB2_Extended::getAfterID (   $id,
  $table,
  $field = null 
)

Returns the autoincrement ID if supported or $id.

Parameters
mixedvalue as returned by getBeforeId()
stringname of the table into which a new row was inserted
stringname of the field into which a new row was inserted
Returns
int|MDB2_Error id on success, a MDB2 error on failure public

Definition at line 700 of file Extended.php.

References MDB2_Module_Common\getDBInstance(), and PEAR\isError().

701  {
702  $db =& $this->getDBInstance();
703  if (PEAR::isError($db)) {
704  return $db;
705  }
706 
707  if ($db->supports('auto_increment') !== true) {
708  return $id;
709  }
710  return $db->lastInsertID($table, $field);
711  }
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getAll()

MDB2_Extended::getAll (   $query,
  $types = null,
  $params = array(),
  $param_types = null,
  $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rekey = false,
  $force_array = false,
  $group = false 
)

Fetch all the rows returned from a query.

Parameters
stringthe SQL query
arraythat contains the types of the columns in the result set
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
intthe fetch mode to use
boolif set to true, the $all will have the first column as its first dimension
bool$force_arrayused only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
bool$groupif 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
array|MDB2_Error data on success, a MDB2 error on failure public

Definition at line 488 of file Extended.php.

References $params, $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2\isResultCommon().

491  {
492  $db =& $this->getDBInstance();
493  if (PEAR::isError($db)) {
494  return $db;
495  }
496 
497  settype($params, 'array');
498  if (empty($params)) {
499  return $db->queryAll($query, $types, $fetchmode, $rekey, $force_array, $group);
500  }
501 
502  $stmt = $db->prepare($query, $param_types, $types);
503  if (PEAR::isError($stmt)) {
504  return $stmt;
505  }
506 
507  $result = $stmt->execute($params);
509  return $result;
510  }
511 
512  $all = $result->fetchAll($fetchmode, $rekey, $force_array, $group);
513  $stmt->free();
514  $result->free();
515  return $all;
516  }
$result
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getAssoc()

MDB2_Extended::getAssoc (   $query,
  $types = null,
  $params = array(),
  $param_types = null,
  $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $force_array = false,
  $group = false 
)

Fetch the entire result set of a query and return it as an associative array using the first column as the key.

If the result set contains more than two columns, the value will be an array of the values from column 2-n. If the result set contains only two columns, the returned value will be a scalar with the value of the second column (unless forced to an array with the $force_array parameter). A MDB2 error code is returned on errors. If the result set contains fewer than two columns, a MDB2_ERROR_TRUNCATED error is returned.

For example, if the table 'mytable' contains:

  ID      TEXT       DATE
--------------------------------
  1       'one'      944679408
  2       'two'      944679408
  3       'three'    944679408

Then the call getAssoc('SELECT id,text FROM mytable') returns:

   array(
     '1' => 'one',
     '2' => 'two',
     '3' => 'three',
   )

...while the call getAssoc('SELECT id,text,date FROM mytable') returns:

   array(
     '1' => array('one', '944679408'),
     '2' => array('two', '944679408'),
     '3' => array('three', '944679408')
   )

If the more than one row occurs with the same value in the first column, the last row overwrites all previous ones by default. Use the $group parameter if you don't want to overwrite like this. Example:

getAssoc('SELECT category,id,name FROM mytable', null, null
          MDB2_FETCHMODE_ASSOC, false, true) returns:
   array(
     '1' => array(array('id' => '4', 'name' => 'number four'),
                  array('id' => '6', 'name' => 'number six')
            ),
     '9' => array(array('id' => '4', 'name' => 'number four'),
                  array('id' => '6', 'name' => 'number six')
            )
   )

Keep in mind that database functions in PHP usually return string values for results regardless of the database's internal type.

Parameters
stringthe SQL query
arraythat contains the types of the columns in the result set
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
bool$force_arrayused only when the query returns exactly two columns. If TRUE, the values of the returned array will be one-element arrays instead of scalars.
bool$groupif 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
array|MDB2_Error data on success, a MDB2 error on failure public

Definition at line 594 of file Extended.php.

References $params, $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2\isResultCommon().

596  {
597  $db =& $this->getDBInstance();
598  if (PEAR::isError($db)) {
599  return $db;
600  }
601 
602  settype($params, 'array');
603  if (empty($params)) {
604  return $db->queryAll($query, $types, $fetchmode, true, $force_array, $group);
605  }
606 
607  $stmt = $db->prepare($query, $param_types, $types);
608  if (PEAR::isError($stmt)) {
609  return $stmt;
610  }
611 
612  $result = $stmt->execute($params);
614  return $result;
615  }
616 
617  $all = $result->fetchAll($fetchmode, true, $force_array, $group);
618  $stmt->free();
619  $result->free();
620  return $all;
621  }
$result
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getBeforeID()

MDB2_Extended::getBeforeID (   $table,
  $field = null,
  $ondemand = true,
  $quote = true 
)

Returns the next free id of a sequence if the RDBMS does not support auto increment.

Parameters
stringname of the table into which a new row was inserted
stringname of the field into which a new row was inserted
boolwhen true the sequence is automatic created, if it not exists
boolif the returned value should be quoted
Returns
int|MDB2_Error id on success, a MDB2 error on failure public

Definition at line 667 of file Extended.php.

References MDB2_Module_Common\getDBInstance(), and PEAR\isError().

668  {
669  $db =& $this->getDBInstance();
670  if (PEAR::isError($db)) {
671  return $db;
672  }
673 
674  if ($db->supports('auto_increment') !== true) {
675  $seq = $table.(empty($field) ? '' : '_'.$field);
676  $id = $db->nextID($seq, $ondemand);
677  if (!$quote || PEAR::isError($id)) {
678  return $id;
679  }
680  return $db->quote($id, 'integer');
681  } elseif (!$quote) {
682  return null;
683  }
684  return 'NULL';
685  }
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getCol()

MDB2_Extended::getCol (   $query,
  $type = null,
  $params = array(),
  $param_types = null,
  $colnum = 0 
)

Fetch a single column from a result set and return it as an indexed array.

Parameters
stringthe SQL query
stringthat contains the type of the column in the result set
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
int|stringwhich column to return
Returns
array|MDB2_Error data on success, a MDB2 error on failure public

Definition at line 433 of file Extended.php.

References $params, $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2\isResultCommon().

435  {
436  $db =& $this->getDBInstance();
437  if (PEAR::isError($db)) {
438  return $db;
439  }
440 
441  settype($params, 'array');
442  settype($type, 'array');
443  if (empty($params)) {
444  return $db->queryCol($query, $type, $colnum);
445  }
446 
447  $stmt = $db->prepare($query, $param_types, $type);
448  if (PEAR::isError($stmt)) {
449  return $stmt;
450  }
451 
452  $result = $stmt->execute($params);
454  return $result;
455  }
456 
457  $col = $result->fetchCol($colnum);
458  $stmt->free();
459  $result->free();
460  return $col;
461  }
$result
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getOne()

MDB2_Extended::getOne (   $query,
  $type = null,
  $params = array(),
  $param_types = null,
  $colnum = 0 
)

Fetch the first column of the first row of data returned from a query.

Takes care of doing the query and freeing the results when finished.

Parameters
stringthe SQL query
stringthat contains the type of the column in the result set
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
int|stringwhich column to return
Returns
scalar|MDB2_Error data on success, a MDB2 error on failure public

Definition at line 340 of file Extended.php.

References $params, $query, $result, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2\isResultCommon().

342  {
343  $db =& $this->getDBInstance();
344  if (PEAR::isError($db)) {
345  return $db;
346  }
347 
348  settype($params, 'array');
349  settype($type, 'array');
350  if (empty($params)) {
351  return $db->queryOne($query, $type, $colnum);
352  }
353 
354  $stmt = $db->prepare($query, $param_types, $type);
355  if (PEAR::isError($stmt)) {
356  return $stmt;
357  }
358 
359  $result = $stmt->execute($params);
361  return $result;
362  }
363 
364  $one = $result->fetchOne($colnum);
365  $stmt->free();
366  $result->free();
367  return $one;
368  }
$result
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ getRow()

MDB2_Extended::getRow (   $query,
  $types = null,
  $params = array(),
  $param_types = null,
  $fetchmode = MDB2_FETCHMODE_DEFAULT 
)

Fetch the first row of data returned from a query.

Takes care of doing the query and freeing the results when finished.

Parameters
stringthe SQL query
arraythat contains the types of the columns in the result set
arrayif supplied, prepare/execute will be used with this array as execute parameters
arraythat contains the types of the values defined in $params
intthe fetch mode to use
Returns
array|MDB2_Error data on success, a MDB2 error on failure public

Definition at line 387 of file Extended.php.

References $params, $query, $result, $row, MDB2_Module_Common\getDBInstance(), PEAR\isError(), and MDB2\isResultCommon().

389  {
390  $db =& $this->getDBInstance();
391  if (PEAR::isError($db)) {
392  return $db;
393  }
394 
395  settype($params, 'array');
396  if (empty($params)) {
397  return $db->queryRow($query, $types, $fetchmode);
398  }
399 
400  $stmt = $db->prepare($query, $param_types, $types);
401  if (PEAR::isError($stmt)) {
402  return $stmt;
403  }
404 
405  $result = $stmt->execute($params);
407  return $result;
408  }
409 
410  $row = $result->fetchRow($fetchmode);
411  $stmt->free();
412  $result->free();
413  return $row;
414  }
$result
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
Definition: MDB2.php:660
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
$params
Definition: example_049.php:96
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

◆ limitQuery()

& MDB2_Extended::limitQuery (   $query,
  $types,
  $limit,
  $offset = 0,
  $result_class = true,
  $result_wrap_class = false 
)

Generates a limited query.

Parameters
stringquery
arraythat contains the types of the columns in the result set
integerthe numbers of rows to fetch
integerthe row to start to fetching
stringwhich specifies which result class to use
mixedstring which specifies which class to wrap results in
Returns
MDB2_Result|MDB2_Error result set on success, a MDB2 error on failure public

Definition at line 267 of file Extended.php.

References $query, $result, MDB2_Module_Common\getDBInstance(), and PEAR\isError().

269  {
270  $db =& $this->getDBInstance();
271  if (PEAR::isError($db)) {
272  return $db;
273  }
274 
275  $result = $db->setLimit($limit, $offset);
276  if (PEAR::isError($result)) {
277  return $result;
278  }
279  $result =& $db->query($query, $types, $result_class, $result_wrap_class);
280  return $result;
281  }
$result
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
Definition: MDB2.php:4238
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:280
+ Here is the call graph for this function:

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