MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Class: MDB2_Extended

Source Location: /MDB2-2.0.0beta6/MDB2/Extended.php

Class Overview

MDB2_Module_Common
   |
   --MDB2_Extended

MDB2_Extended: class which adds several high level methods to MDB2


Author(s):

Methods


Inherited Variables

Inherited Methods

Class: MDB2_Module_Common

MDB2_Module_Common::MDB2_Module_Common()
MDB2_Module_Common::getDBInstance()
get the instance of MDB2 associated with the module instance

Class Details

[line 66]
MDB2_Extended: class which adds several high level methods to MDB2


[ Top ]


Method Detail

autoExecute   [line 119]

mixed &autoExecute( string $table, array $fields_values, [int $mode = MDB2_AUTOQUERY_INSERT], [string $where = false], [mixed $types = null], [mixed $result_types = null], [mixed $result_class = true])

Make automaticaly an insert or update query and call prepare() and execute() with it

Parameters:

string   $table     name of the table
array   $fields_values     assoc ($key=>$value) where $key is a field name and $value its value
int   $mode     type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement
mixed   $types     array that contains the types of the placeholders
mixed   $result_types     array that contains the types of the columns in the result set
mixed   $result_class     string which specifies which result class to use

[ Top ]

autoPrepare   [line 85]

resource autoPrepare( string $table, array $table_fields, [int $mode = MDB2_AUTOQUERY_INSERT], [string $where = false], [mixed $types = null], [mixed $result_types = null])

Make automaticaly an insert or update query and call prepare() with it

Parameters:

string   $table     name of the table
array   $table_fields     ordered array containing the fields names
int   $mode     type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement
mixed   $types     array that contains the types of the placeholders
mixed   $result_types     array that contains the types of the columns in the result set

[ Top ]

buildManipSQL   [line 152]

string buildManipSQL( string $table, array $table_fields, int $mode, [string $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 query, all the records of the table will be updated !

  • Return: sql query for prepare()
  • Access: public

Parameters:

string   $table     name of the table
array   $table_fields     ordered array containing the fields names
int   $mode     type of query to make (MDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE)
string   $where     in case of update queries, this string will be put after the sql WHERE statement

[ Top ]

executeMultiple   [line 535]

mixed executeMultiple( resource &$stmt, [array $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.

  • Return: a result handle or MDB2_OK on success, a MDB2 error on failure
  • See: prepare(), execute()
  • Access: public

Parameters:

resource   $stmt     query handle from prepare()
array   $params     numeric array containing the data to insert into the query

[ Top ]

getAfterID   [line 591]

mixed getAfterID( mixed $id, string $table, mixed $field)

returns the autoincrement ID if supported or $id
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

mixed   $id     value as returned by getBeforeId()
string   $table     name of the table into which a new row was inserted

[ Top ]

getAll   [line 383]

mixed getAll( string $query, [array $types = null], [array $params = array()], [array $param_types = null], [integer $fetchmode = MDB2_FETCHMODE_DEFAULT], [boolean $rekey = false], [boolean $force_array = false], [boolean $group = false])

Fetch all the rows returned from a query.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query
array   $types     array that contains the types of the columns in the result set
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
array   $param_types     array that contains the types of the values defined in $params
integer   $fetchmode     the fetch mode to use
boolean   $rekey     if set to true, the $all will have the first column as its first dimension
boolean   $force_array     used only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
boolean   $group     if 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.

[ Top ]

getAssoc   [line 487]

array getAssoc( string $query, [array $types = null], [array $params = array()], [array $param_types = null], [mixed $fetchmode = MDB2_FETCHMODE_DEFAULT], [boolean $force_array = false], [boolean $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 MDB 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.

  • Return: associative array with results from the query.
  • Access: public

Parameters:

string   $query     the SQL query
array   $types     array that contains the types of the columns in the result set
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
array   $param_types     array that contains the types of the values defined in $params
boolean   $force_array     used only when the query returns exactly two columns. If TRUE, the values of the returned array will be one-element arrays instead of scalars.
boolean   $group     if 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.

[ Top ]

getBeforeID   [line 562]

mixed getBeforeID( string $table, mixed $field, [boolean $ondemand = true])

returns the next free id of a sequence if the RDBMS does not support auto increment
  • Return: MDB2 Error Object or id
  • Access: public

Parameters:

string   $table     name of the table into which a new row was inserted
boolean   $ondemand     when true the seqence is automatic created, if it not exists

[ Top ]

getCol   [line 326]

mixed getCol( string $query, [string $type = null], [array $params = array()], [array $param_types = null], [mixed $colnum = 0])

Fetch a single column from a result set and return it as an indexed array.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query
string   $type     string that contains the type of the column in the result set
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
array   $param_types     array that contains the types of the values defined in $params
mixed   $colnum     which column to return

[ Top ]

getOne   [line 229]

mixed getOne( string $query, [string $type = null], [array $params = array()], [array $param_types = null], [mixed $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.
  • Return: MDB2_OK or data on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query
string   $type     string that contains the type of the column in the result set
array   $params     if supplied, prepare/execute will be used with this array as execute parameters
array   $param_types     array that contains the types of the values defined in $params
mixed   $colnum     which column to return

[ Top ]

getRow   [line 278]

mixed getRow( string $query, [array $types = null], [array $params = array()], [array $param_types = null], [integer $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.
  • Return: MDB2_OK or data array on success, a MDB2 error on failure
  • Access: public

Parameters:

string   $query     the SQL query
array   $types     array that contains the types of the columns in the result set
array   $params     array if supplied, prepare/execute will be used with this array as execute parameters
array   $param_types     array that contains the types of the values defined in $params
integer   $fetchmode     the fetch mode to use

[ Top ]

limitQuery   [line 195]

mixed &limitQuery( string $query, mixed $types, integer $count, [integer $from = 0], [mixed $result_class = true])

Generates a limited query
  • Return: a valid ressource pointer or a MDB2 Error Object
  • Access: public

Parameters:

string   $query     query
mixed   $types     array that contains the types of the columns in the result set
integer   $from     the row to start to fetching
integer   $count     the numbers of rows to fetch
mixed   $result_class     string which specifies which result class to use

[ Top ]


Documentation generated on Mon, 10 Oct 2005 07:01:17 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.