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

Class: DB_DataObject

Source Location: /DB_DataObject-1.11.5/DB/DataObject.php

Class Overview


storage for connection and result objects, it is done this way so that print_r()'ing the is smaller, and it reduces the memory size of the object.



Child classes:

Generator class

Inherited Variables

Inherited Methods

Class Details

[line 214]
storage for connection and result objects, it is done this way so that print_r()'ing the is smaller, and it reduces the memory size of the object.

-- future versions may use $this->_connection = & PEAR object.. although will need speed tests to see how this affects it.

    • connections = md5 sum mapp to pear db object
    • results = [id] => map to pear db object
    • resultseq = sequence id for results & results field
    • resultfields = [id] => list of fields return from query (for use with toArray())
    • ini = mapping of database to ini file results
    • links = mapping of database to links file
    • lasterror = pear error objects for last error event.
    • config = aliased view of PEAR::getStaticPropery('DB_DataObject','options') * done for performance.
    • array of loaded classes by autoload method - to stop it doing file access request over and over again!

    [ Top ]

    Class Variables

    $N =  0

    [line 238]

    The Number of rows returned from a query
    • Access: public

    Type:   int

    [ Top ]

    $_lastError =  false

    [line 4671]

    Last Error that has occured
    • use $this->_lastError or
    $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
    • Var: (or false)
    • Access: public

    Type:   object PEAR_Error

    [ Top ]

    $_resultFields =  false

    [line 1874]

    ResultFields - on the last call to fetch(), resultfields is sent here, so we can clean up the memory.
    • Access: public

    Type:   array

    [ Top ]

    Method Detail

    autoJoin   [line 3804]

    array autoJoin( [array $cfg = array()])

    autoJoin - using the links.ini file, it builds a query with all the joins

    usage: $x = DB_DataObject::factory('mytable'); $x->autoJoin(); $x->get(123); will result in all of the joined data being added to the fetched object..

    $x = DB_DataObject::factory('mytable'); $x->autoJoin(); $ar = $x->fetchAll(); will result in an array containing all the data from the table, and any joined tables..

    $x = DB_DataObject::factory('mytable'); $jdata = $x->autoJoin(); $x->selectAdd(); //reset.. foreach($_REQUEST['requested_cols'] as $c) { if (!isset($jdata[$c])) continue; // ignore columns not available.. $x->selectAdd( $jdata[$c] . ' as ' . $c); } $ar = $x->fetchAll(); will result in only the columns requested being fetched...

    • Return: info about joins cols => map of resulting {joined_tablename}.{joined_table_column_name} join_names => map of resulting {join_name_as}.{joined_table_column_name} count => the column to count on.
    • Access: public


    array   $cfg   —  Configuration exclude Array of columns to exclude from results (eg. modified_by_id) links The equivilant links.ini data for this table eg. array( 'person_id' => 'person:id', .... ) include Array of columns to include distinct Array of distinct columns.

    [ Top ]

    count   [line 1695]

    int count( [bool|string $countWhat = false], [bool $whereAddOnly = false])

    Find the number of results from a simple query

    for example

    $object = new mytable(); $object->name = "fred"; echo $object->count(); echo $object->count(true); // dont use object vars. echo $object->count('distinct mycol'); count distinct mycol. echo $object->count('distinct mycol',true); // dont use object vars. echo $object->count('distinct'); // count distinct id (eg. the primary key)

    • Access: public


    bool   $whereAddOnly   —  (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then we will build the condition only using the whereAdd's. Default is to build the condition using the object parameters as well.
    bool|string   $countWhat   —  (optional) (true|false => see below not on whereAddonly) (string) "DISTINCT" => does a distinct count on the tables 'key' column otherwise => normally it counts primary keys - you can use this to do things like $do->count('distinct mycol');

    [ Top ]

    database   [line 2092]

    string database( string 0)

    Return or assign the name of the current database
    • Return: The name of the current database
    • Access: public


    string   0   —  optional database name to set

    [ Top ]

    databaseStructure   [line 1903]

    true databaseStructure( optional 0, optional 1, optional 2)

    Autoload or manually load the table definitions

    usage : DB_DataObject::databaseStructure( 'databasename', parse_ini_file('mydb.ini',true), parse_ini_file('mydb.link.ini',true));

    obviously you dont have to use ini files.. (just return array similar to ini files..)

    It should append to the table structure array

    • Return: or PEAR:error on wrong paramenters.. or false if no file exists.. or the array(tablename => array(column_name=>type)) if called with 1 argument.. (databasename)
    • Access: public


    optional   0   —  string name of database to assign / read
    optional   1   —  array structure of database, and keys
    optional   2   —  array table links

    [ Top ]

    debug   [line 4610]

    none debug( string $message, [string $logtype = 0], [string $level = 1])

    Debugger. - use this in your extended classes to output debugging information.

    Uses DB_DataObject::DebugLevel(x) to turn it on

    • Access: public


    string   $message   —  - message to output
    string   $logtype   —  - bold at start
    string   $level   — 
    • output level

    [ Top ]

    debugLevel   [line 4649]

    none debugLevel( [int $v = null])

    sets and returns debug level eg. DB_DataObject::debugLevel(4);
    • Access: public


    int   $v   —  level

    [ Top ]

    delete   [line 1535]

    mixed delete( [bool $useWhere = false])

    Deletes items from table which match current objects variables

    Returns the true on success

    for example

    Designed to be extended

    $object = new mytable(); $object->ID=123; echo $object->delete(); // builds a conditon

    $object = new mytable(); $object->whereAdd('age > 12'); $object->limit(1); $object->orderBy('age DESC'); $object->delete(true); // dont use object vars, use the conditions, limit and order.

    • Return: Int (No. of rows affected) on success, false on failure, 0 on no data affected
    • Access: public


    bool   $useWhere   —  (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then we will build the condition only using the whereAdd's. Default is to build the condition only using the object parameters.

    [ Top ]

    escape   [line 1784]

    string escape( string $string, [bool $likeEscape = false])

    an escape wrapper around DB->escapeSimple() can be used when adding manual queries or clauses eg.

    $object->query("select * from xyz where abc like '". $object->escape($_GET['name']) . "'");

    • Access: public


    string   $string   —  value to be escaped
    bool   $likeEscape   —  escapes % and _ as well. - so like queries can be protected.

    [ Top ]

    fetch   [line 511]

    boolean fetch( )

    fetches next row into this objects var's

    returns 1 on success 0 on failure

    Example $object = new mytable(); $object->name = "fred"; $object->find(); $store = array(); while ($object->fetch()) { echo $this->ID; $store[] = $object; // builds an array of object lines. }

    to add features to a fetch function fetch () { $ret = parent::fetch(); $this->date_formated = date('dmY',$this->date); return $ret; }

    • Return: on success
    • Access: public

    [ Top ]

    fetchAll   [line 641]

    array fetchAll( [string|false $k = false], [string|false $v = false], [string|false $method = false])

    fetches all results as an array,

    return format is dependant on args. if selectAdd() has not been called on the object, then it will add the correct columns to the query.

    A) Array of values (eg. a list of 'id')

    $x = DB_DataObject::factory('mytable'); $x->whereAdd('something = 1') $ar = $x->fetchAll('id'); -- returns array(1,2,3,4,5)

    B) Array of values (not from table)

    $x = DB_DataObject::factory('mytable'); $x->whereAdd('something = 1'); $x->selectAdd(); $x->selectAdd('distinct(group_id) as group_id'); $ar = $x->fetchAll('group_id'); -- returns array(1,2,3,4,5) * C) A key=>value associative array

    $x = DB_DataObject::factory('mytable'); $x->whereAdd('something = 1') $ar = $x->fetchAll('id','name'); -- returns array(1=>'fred',2=>'blogs',3=> .......

    D) array of objects $x = DB_DataObject::factory('mytable'); $x->whereAdd('something = 1'); $ar = $x->fetchAll();

    E) array of arrays (for example) $x = DB_DataObject::factory('mytable'); $x->whereAdd('something = 1'); $ar = $x->fetchAll(false,false,'toArray');

    • Return: format dependant on arguments, may be empty
    • Access: public


    string|false   $k   —  key
    string|false   $v   —  value
    string|false   $method   —  method to call on each result to get array value (eg. 'toArray')

    [ Top ]

    fetchRow   [line 1617]

    boolean fetchRow( [int $row = null])

    fetches a specific row into this object variables

    Not recommended - better to use fetch()

    Returens true on success

    • Return: true on success
    • Access: public


    int   $row   —  row

    [ Top ]

    find   [line 396]

    mixed find( [boolean $n = false])

    find results, either normal or crosstable

    for example

    $object = new mytable(); $object->ID = 1; $object->find();

    will set $object->N to number of rows, and expects next command to fetch rows will return $object->N

    if an error occurs $object->N will be set to false and return value will also be false; if numRows is not supported it will

    • Return: (number of rows returned, or true if numRows fetching is not supported)
    • Access: public


    boolean   $n   —  Fetch first result

    [ Top ]

    free   [line 4746]

    none free( )

    Free global arrays associated with this object.
    • Access: public

    [ Top ]

    fromValue   [line 4425]

    true| fromValue( string $col, mixed $value)

    standard set* implementation.

    takes data and uses it to set dates/strings etc. normally called from __call..

    Current supports date = using (standard time format, or unixtimestamp).... so you could create a method : function setLastread($string) { $this->fromValue('lastread',strtotime($string)); }

    time = using strtotime datetime = using same as date - accepts iso standard or unixtimestamp. string = typecast only..

    TODO: add formater:: eg. d/m/Y for date! ???

    • Return: false (False on error)
    • See: DB_DataObject::_call
    • Access: public


    string   $col   —  column of database
    mixed   $value   —  value to assign

    [ Top ]

    get   [line 265]

    int get( [string $k = null], [string $v = null])

    Get a result using key, value.

    for example $object->get("ID",1234); Returns Number of rows located (usually 1) for success, and puts all the table columns into this classes variables

    see the fetch example on how to extend this.

    if no value is entered, it is assumed that $key is a value and get will then use the first key in keys() to obtain the key.

    • Return: No. of rows
    • Access: public


    string   $k   —  column
    string   $v   —  value

    [ Top ]

    getDatabaseConnection   [line 4276]

    object The getDatabaseConnection( )

    Gets the DB object related to an object - so you can use funky peardb stuf with it :)
    • Return: DB connection
    • Access: public

    [ Top ]

    getDatabaseResult   [line 4299]

    object The getDatabaseResult( )

    Gets the DB result object related to the objects active query
    • so you can use funky pear stuff with it - like pager for example.. :)

    • Return: DB result object
    • Access: public

    [ Top ]

    getLink   [line 3232]

    void getLink( $row, [ $table = null], [ $link = false])

    deprecited : @use link()


       $row   — 
       $table   — 
       $link   — 

    [ Top ]

    getLinkArray   [line 3268]

    array getLinkArray( $row, [string $table = null], string $column)

    getLinkArray Fetch an array of related objects. This should be used in conjunction with a <dbname>.links.ini file configuration (see the introduction on linking for details on this).

    You may also use this with all parameters to specify, the column and related table. This is highly dependant on naming columns 'correctly' :) using colname = xxxxx_yyyyyy xxxxxx = related table; (yyyyy = user defined..) looks up table xxxxx, for value id=$this->xxxxx stores it in $this->_xxxxx_yyyyy

    • Return:

      - array of results (empty array on failure)

      Example - Getting the related objects

      $person = new DataObjects_Person; $person->get(12); $children = $person->getLinkArray('children');

      echo 'There are ', count($children), ' descendant(s):
      '; foreach ($children as $child) { echo $child->name, '
      '; }

    • Access: public


    string   $column   —  - either column or column.xxxxx
    string   $table   —  - name of table to look up value in
       $row   — 

    [ Top ]

    getLinks   [line 3221]

    boolean getLinks( [string $format = '_%s'])

    load related objects

    Generally not recommended to use this. The generator should support creating getter_setter methods which are better suited.

    Relies on <dbname>.links.ini

    Sets properties on the calling dataobject you can change what object vars the links are stored in by changeing the format parameter

    • Return: , true on success
    • Author: Tim White <tim@cyface.com>
    • Access: public


    string   $format   —  format (default _%s) where %s is the table name.

    [ Top ]

    groupBy   [line 805]

    none|PEAR::Error groupBy( [string $group = false])

    Adds a group by condition

    $object->groupBy(); //reset the grouping $object->groupBy("ID DESC"); $object->groupBy("ID,age");

    • Return: - invalid args only
    • Access: public


    string   $group   —  Grouping

    [ Top ]

    having   [line 840]

    none|PEAR::Error having( [string $having = false])

    Adds a having clause

    $object->having(); //reset the grouping $object->having("sum(value) > 0 ");

    • Return: - invalid args only
    • Access: public


    string   $having   —  condition

    [ Top ]

    insert   [line 1056]

    mixed insert( )

    Insert the current objects variables into the database

    Returns the ID of the inserted element (if auto increment or sequences are used.)

    for example

    Designed to be extended

    $object = new mytable(); $object->name = "fred"; echo $object->insert();

    • Return: false on failure, int when auto increment or sequence used, otherwise true on success
    • Access: public

    [ Top ]

    joinAdd   [line 3389]

    none joinAdd( [optional $obj = false], [optional $joinType = 'INNER'], [optional $joinAs = false], [optional $joinCol = false])

    joinAdd - adds another dataobject to this, building a joined query.

    example (requires links.ini to be set up correctly) // get all the images for product 24 $i = new DataObject_Image(); $pi = new DataObjects_Product_image(); $pi->product_id = 24; // set the product id to 24 $i->joinAdd($pi); // add the product_image connectoin $i->find(); while ($i->fetch()) { // do stuff } // an example with 2 joins // get all the images linked with products or productgroups $i = new DataObject_Image(); $pi = new DataObject_Product_image(); $pgi = new DataObject_Productgroup_image(); $i->joinAdd($pi); $i->joinAdd($pgi); $i->find(); while ($i->fetch()) { // do stuff }


    optional   $obj   —  object |array the joining object (no value resets the join) If you use an array here it should be in the format: array('local_column','remotetable:remote_column'); if remotetable does not have a definition, you should use @ to hide the include error message.. array('local_column', $dataobject , 'remote_column'); if array has 3 args, then second is assumed to be the linked dataobject.
    optional   $joinType   — 

    string | array 'LEFT'|'INNER'|'RIGHT'|'' Inner is default, '' indicates just select ... from a,b,c with no join and links are added as where items.

    If second Argument is array, it is assumed to be an associative array with arguments matching below = eg. 'joinType' => 'INNER', 'joinAs' => '...' 'joinCol' => .... 'useWhereAsOn' => false,

    optional   $joinAs   —  string if you want to select the table as anther name useful when you want to select multiple columsn from a secondary table.
    optional   $joinCol   — 

    string The column on This objects table to match (needed if this table links to the child object in multiple places eg. user->friend (is a link to another user) user->mother (is a link to another user..)

    optional 'useWhereAsOn' bool default false; convert the where argments from the object being added into ON arguments.

    [ Top ]

    keys   [line 2157]

    array keys( string 0, * 1)

    get/set an array of table primary keys

    set usage: $do->keys('id','code');

    This is defined in the table definition if it gets it wrong, or you do not want to use ini tables, you can override this.

    • Access: public


    string   0   —  optional set the key
    *   1   —  optional set more keys

    [ Top ]

    limit   [line 918]

    none|PEAR::Error limit( [string $a = null], [string $b = null])

    Sets the Limit

    $boject->limit(); // clear limit $object->limit(12); $object->limit(12,10);

    Note this will emit an error on databases other than mysql/postgress as there is no 'clean way' to implement it. - you should consider refering to your database manual to decide how you want to implement it.

    • Return: - invalid args only
    • Access: public


    string   $a   —  limit start (or number), or blank to reset
    string   $b   —  number

    [ Top ]

    link   [line 3196]

    mixed link( $field, [ $set_args = array()], mixed $link_spec, mixed $set_value)

    generic getter/setter for links

    This is the new 'recommended' way to get get/set linked objects. must be used with links.ini

    usage: get: $obj = $do->link('company_id'); $obj = $do->link(array('local_col', 'linktable:linked_col'));

    set: $do->link('company_id',0); $do->link('company_id',$obj); $do->link('company_id', array($obj));

    example function

    function company() { $this->link(array('company_id','company:id'), func_get_args()); }

    • Return: true or false on setting, object on getting
    • Author: Alan Knowles
    • Access: public


    mixed   $link_spec   —  link specification (normally a string) uses similar rules to joinAdd() array argument.
    mixed   $set_value   —  (optional) int, DataObject, or array('set')
       $field   — 
       $set_args   — 

    [ Top ]

    links   [line 3052]

    array|null links( array $new_links)

    Get the links associate array as defined by the links.ini file.

    Experimental... - Should look a bit like [local_col_name] => "related_tablename:related_col_name"

    • Return: array = if there are links defined for this table. empty array - if there is a links.ini file, but no links on this table false - if no links.ini exists for this database (hence try auto_links).
    • See: DB_DataObject::getLinks(), DB_DataObject::getLink()
    • Access: public


    array   $new_links   —  optional - force update of the links for this table You probably want to restore it to it's original state after, as modifying here does it for the whole PHP request.

    [ Top ]

    orderBy   [line 770]

    none|PEAR::Error orderBy( [string $order = false])

    Adds a order by condition

    $object->orderBy(); //clears order by $object->orderBy("ID"); $object->orderBy("ID,age");

    • Return: - invalid args only
    • Access: public


    string   $order   —  Order

    [ Top ]

    pid   [line 306]

    the pid( )

    Get the value of the primary id

    While I normally use 'id' as the PRIMARY KEY value, some database use {table}_id as the column name.

    To save a bit of typing,

    $id = $do->pid();

    • Return: id

    [ Top ]

    query   [line 1767]

    void query( string $string)

    sends raw query to database

    Since _query has to be a private 'non overwriteable method', this is a relay

    • Return: or DB_Error
    • Access: public


    string   $string   —  SQL Query

    [ Top ]

    raiseError   [line 4684]

    error raiseError( int $message, [int $type = null], [int $behaviour = null])

    Default error handling is to create a pear error, but never return it.

    if you need to handle errors you should look at setting the PEAR_Error callback this is due to the fact it would wreck havoc on the internal methods!

    • Return: object
    • Access: public


    int   $message   —  message
    int   $type   —  type
    int   $behaviour   —  behaviour (die or continue!);

    [ Top ]

    selectAdd   [line 961]

    mixed selectAdd( [string $k = null])

    Adds a select columns

    $object->selectAdd(); // resets select to nothing! $object->selectAdd("*"); // default select $object->selectAdd("unixtime(DATE) as udate"); $object->selectAdd("DATE");

    to prepend distict: $object->selectAdd('distinct ' . $object->selectAdd());

    • Return: null or old string if you reset it.
    • Access: public


    string   $k   — 

    [ Top ]

    selectAs   [line 1001]

    void selectAs( [array|object|null $from = null], [string $format = '%s'], [string $tableName = false])

    Adds multiple Columns or objects to select with formating.

    $object->selectAs(null); // adds "table.colnameA as colnameA,table.colnameB as colnameB,......" // note with null it will also clear the '*' default select $object->selectAs(array('a','b'),'%s_x'); // adds "a as a_x, b as b_x" $object->selectAs(array('a','b'),'ddd_%s','ccc'); // adds "ccc.a as ddd_a, ccc.b as ddd_b" $object->selectAdd($object,'prefix_%s'); // calls $object->get_table and adds it all as objectTableName.colnameA as prefix_colnameA

    • Access: public


    array|object|null   $from   —  the array or object to take column names from.
    string   $format   —  format in sprintf format (use %s for the colname)
    string   $tableName   —  table name eg. if you have joinAdd'd or send $from as an array.

    [ Top ]

    sequenceKey   [line 2197]

    array sequenceKey( string 0, boolean 1, false|string 2)

    get/set an sequence key

    by default it returns the first key from keys() set usage: $do->sequenceKey('id',true);

    override this to return array(false,false) if table has no real sequence key.

    • Return: (column,use_native,sequence_name)
    • Access: public


    string   0   —  optional the key sequence/autoinc. key
    boolean   1   —  optional use native increment. default false
    false|string   2   —  optional native sequence name

    [ Top ]

    setFrom   [line 4026]

    true setFrom( array $from, [string $format = '%s'], [boolean $skipEmpty = false])

    Copies items that are in the table definitions from an array or object into the current object will not override key values.
    • Return: on success or array of key=>setValue error message
    • Access: public


    string   $format   —  eg. map xxxx_name to $object->name using 'xxxx_%s' (defaults to %s - eg. name -> $object->name
    boolean   $skipEmpty   —  (dont assign empty values if a column is empty (eg. '' / 0 etc...)
    array   $from   —  | object $from

    [ Top ]

    sqlValue   [line 4001]

    void sqlValue( string $value, string $callvalue)

    Factory method for calling DB_DataObject_Cast

    if used with 1 argument DB_DataObject_Cast::sql($value) is called

    if used with 2 arguments DB_DataObject_Cast::$value($callvalue) is called valid first arguments are: blob, string, date, sql

    eg. $member->updated = $member->sqlValue('NOW()');

    might handle more arguments for escaping later...


    string   $value   —  (or type if used with 2 arguments)
    string   $callvalue   —  (optional) used with date/null etc..

    [ Top ]

    staticGet   [line 4831]

    void staticGet( $class, $k, [ $v = null])

    (deprecated - use ::get / and your own caching method)


       $class   — 
       $k   — 
       $v   — 

    [ Top ]

    table   [line 2111]

    array table( array 0)

    get/set an associative array of table columns
    • Return: (associative)
    • Access: public


    array   0   —  key=>type array

    [ Top ]

    tableName   [line 2069]

    string tableName( string 0)

    Return or assign the name of the current table
    • Return: The name of the current table
    • Access: public


    string   0   —  optinal table name to set

    [ Top ]

    toArray   [line 4125]

    array toArray( [string $format = '%s'], [bool||number $hideEmpty = false])

    Returns an associative array from the current data (kind of oblivates the idea behind DataObjects, but is usefull if you use it with things like QuickForms.

    you can use the format to return things like user[key] by sending it $object->toArray('user[%s]')

    will also return links converted to arrays.

    • Return: of key => value for row
    • Access: public


    string   $format   —  sprintf format for array
    bool||number   $hideEmpty   —  [true = elemnts that have a value set], [false = table + returned colums] , [0 = returned columsn only]

    [ Top ]

    toValue   [line 4528]

    true toValue( string $col, [format $format = null])

    standard get* implementation.

    with formaters.. supported formaters: date/time : %d/%m/%Y (eg. php strftime) or pear::Date numbers : %02d (eg. sprintf) NOTE you will get unexpected results with times like 0000-00-00 !!!

    • Return: Description
    • See: DB_DataObject::_call(), strftime(), Date::format()
    • Access: public


    string   $col   —  column of database
    format   $format   —  foramt

    [ Top ]

    unionAdd   [line 3303]

    $obj unionAdd( $obj $obj, [optional $is_all = ''])

    unionAdd - adds another dataobject to this, building a unioned query.

    usage: $doTable1 = DB_DataObject::factory("table1"); $doTable2 = DB_DataObject::factory("table2");

    $doTable1->selectAdd(); $doTable1->selectAdd("col1,col2"); $doTable1->whereAdd("col1 > 100"); $doTable1->orderBy("col1");

    $doTable2->selectAdd(); $doTable2->selectAdd("col1, col2"); $doTable2->whereAdd("col2 = 'v'");

    $doTable1->unionAdd($doTable2); $doTable1->find();

    Note: this model may be a better way to implement joinAdd?, eg. do the building in find?

    • Return: object|array the added object, or old list if reset.


    optional   $is_all   —  string 'ALL' to do all.
    $obj   $obj   —  object|false the union object or false to reset

    [ Top ]

    update   [line 1331]

    int update( [object dataobject $dataObject = false])

    Updates current objects variables into the database uses the keys() to decide how to update Returns the true on success

    for example

    $object = DB_DataObject::factory('mytable'); $object->get("ID",234); $object->email="testing@test.com"; if(!$object->update()) echo "UPDATE FAILED";

    to only update changed items : $dataobject->get(132); $original = $dataobject; // clone/copy it.. $dataobject->setFrom($_POST); if ($dataobject->validate()) { $dataobject->update($original); } // otherwise an error...

    performing global updates: $object = DB_DataObject::factory('mytable'); $object->status = "dead"; $object->whereAdd('age > 150'); $object->update(DB_DATAOBJECT_WHEREADD_ONLY);

    • Return: rows affected or false on failure
    • Access: public


    object dataobject   $dataObject   —  (optional) | DB_DATAOBJECT_WHEREADD_ONLY - used to only update changed items.

    [ Top ]

    useIndex   [line 878]

    none|PEAR::Error useIndex( [string|array $index = false])

    Adds a using Index

    $object->useIndex(); //reset the use Index $object->useIndex("some_index");

    Note do not put unfiltered user input into theis method. This is mysql specific at present? - might need altering to support other databases.

    • Return: - invalid args only
    • Access: public


    string|array   $index   —  index or indexes to use.

    [ Top ]

    validate   [line 4193]

    array validate( )

    validate the values of the object (usually prior to inserting/updating..)

    Note: This was always intended as a simple validation routine. It lacks understanding of field length, whether you are inserting or updating (and hence null key values)

    This should be moved to another class: DB_DataObject_Validate FEEL FREE TO SEND ME YOUR VERSION FOR CONSIDERATION!!!

    Usage: if (is_array($ret = $obj->validate())) { ... there are problems with the data ... }


    • defaults to only testing strings/numbers if numbers or strings are the correct type and null values are correct
    • validate Column methods : "validate{ROWNAME}()" are called if they are defined. These methods should return true = everything ok false|object = something is wrong!
    • This method loads and uses the PEAR Validate Class.

    • Return: of validation results (where key=>value, value=false|object if it failed) or true (if they all succeeded)
    • Access: public

    [ Top ]

    whereAdd   [line 685]

    string|PEAR::Error whereAdd( [string $cond = false], [string $logic = 'AND'])

    Adds a condition to the WHERE statement, defaults to AND

    $object->whereAdd(); //reset or cleaer ewhwer $object->whereAdd("ID > 20"); $object->whereAdd("age > 20","OR");

    • Return: - previous condition or Error when invalid args found
    • Access: public


    string   $cond   —  condition
    string   $logic   —  optional logic "OR" (defaults to "AND")

    [ Top ]

    whereAddIn   [line 731]

    string|PEAR::Error whereAddIn( string $key, array $list, string $type, [string $logic = 'AND'])

    Adds a 'IN' condition to the WHERE statement

    $object->whereAddIn('id', $array, 'int'); //minimal usage $object->whereAddIn('price', $array, 'float', 'OR'); // cast to float, and call whereAdd with 'OR' $object->whereAddIn('name', $array, 'string'); // quote strings

    • Return: - previous condition or Error when invalid args found
    • Access: public


    string   $key   —  key column to match
    array   $list   —  list of values to match
    string   $type   —  string|int|integer|float|bool cast to type.
    string   $logic   —  optional logic to call whereAdd with eg. "OR" (defaults to "AND")

    [ Top ]

    _call   [line 4334]

    true? _call( $method, $params, &$return)

    Overload Extension support
    • enables setCOLNAME/getCOLNAME
    if you define a set/get method for the item it will be called.

    otherwise it will just return/set the value. NOTE this currently means that a few Names are NO-NO's eg. links,link,linksarray, from, Databaseconnection,databaseresult


      • get is automatically called by toArray()
      setters return true on success. = strings on failure getters return the value!

      this fires off trigger_error - if any problems.. pear_error, has problems with 4.3.2RC2 here

      • See: overload
      • Access: public


         $method   — 
         $params   — 
         &$return   — 

      [ Top ]

      _loadConfig   [line 4731]

      object an _loadConfig( )

      Define the global $_DB_DATAOBJECT['CONFIG'] as an alias to PEAR::getStaticProperty('DB_DataObject','options');

      After Profiling DB_DataObject, I discoved that the debug calls where taking considerable time (well 0.1 ms), so this should stop those calls happening. as all calls to debug are wrapped with direct variable queries rather than actually calling the funciton THIS STILL NEEDS FURTHER INVESTIGATION

      • Return: error object
      • Access: public

      [ Top ]

      Documentation generated on Wed, 09 Dec 2015 23:16:05 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.