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

Class: DB_QueryTool_Query

Source Location: /DB_QueryTool-1.0.0/QueryTool/Query.php

Class Overview


DB_QueryTool_Query class


Author(s):

Copyright:

  • 2003-2005 Wolfram Kriesing, Paolo Panto, Lorenzo Alberton

Variables

Methods


Child classes:

DB_QueryTool_EasyJoin
DB_QueryTool_EasyJoin class

Inherited Variables

Inherited Methods


Class Details

[line 46]
DB_QueryTool_Query class

This class should be extended



[ Top ]


Class Variables

$db =  null

[line 68]

  • Var: db-object, a PEAR::DB instance

Type:   object the


[ Top ]

$primaryCol =  'id'

[line 53]

  • Var: the name of the primary column

Type:   string


[ Top ]

$sequenceName =  null

[line 63]

  • Var: the name of the sequence for this table

Type:   string


[ Top ]

$table =  ''

[line 58]

  • Var: the current table the class works on

Type:   string


[ Top ]

$tableSpec = array()

[line 171]

this array contains information about the tables those are
  • 'name' => the real table name
  • 'shortName' => the short name used, so that when moving the table i.e.

onto a provider's db and u have to rename the tables to longer names this name will be relevant, i.e. when autoJoining, i.e. a table name on your local machine is: 'user' but online it has to be 'applName_user' then the shortName will be used to determine if a column refers to another table, if the colName is 'user_id', it knows the shortName 'user' refers to the table 'applName_user'


Type:   mixed


[ Top ]



Method Detail

DB_QueryTool_Query (Constructor)   [line 252]

DB_QueryTool_Query DB_QueryTool_Query( [mixed $dsn = false], [array $options = array()])

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/02
  • Access: public

Parameters:

mixed   $dsn   —  DSN string, DSN array or DB object
array   $options   — 

[ Top ]

add   [line 632]

mixed add( array $newData)

add a new member in the DB
  • Return: the inserted id on success, or false otherwise
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/02
  • Access: public

Parameters:

array   $newData   —  contains the new data that shall be saved in the DB

[ Top ]

addHaving   [line 1037]

void addHaving( [string $what = '*'], [string $connectString = ' AND '])

Extend the current having clause. This is very useful, when you are building this clause from different places and don't want to overwrite the currently set having clause, but extend it.

Parameters:

string   $what   —  this is a having clause, i.e. 'column' or 'table.column' or 'MAX(column)'
string   $connectString   —  the connection string, which usually stays the default, which is ',' (a comma)

[ Top ]

addJoin   [line 1197]

void addJoin( string $table, string $where, [string $type = 'default'])

adds a table and a where clause that shall be used for the join

instead of calling setJoin(array(table1,table2),'<where clause1> AND <where clause2>') you can also call setJoin(table1,'<where clause1>') addJoin(table2,'<where clause2>') or where it makes more sense is to build a query which is made out of a left join and a standard join setLeftJoin(table1,'<where clause1>') // results in ... FROM $this->table LEFT JOIN table ON <where clause1> addJoin(table2,'<where clause2>') // results in ... FROM $this->table,table2 LEFT JOIN table ON <where clause1> WHERE <where clause2>

  • Access: public

Parameters:

string   $table   —  the table to be joined
string   $where   —  the where clause for the join
string   $type   —  the join type

[ Top ]

addLeftJoin   [line 1109]

void addLeftJoin( string $table, string $where, [string $type = 'left'])


Parameters:

string   $table   —  the table to be left-joined
string   $where   —  the where clause for the join
string   $type   —  the join type

[ Top ]

addMultiple   [line 674]

mixed addMultiple( array $data)

adds multiple new members in the DB
  • Return: the inserted ids on success, or false otherwise
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/17
  • Access: public

Parameters:

array   $data   —  contains an array of new data that shall be saved in the DB the key-value pairs have to be the same for all the data!!!

[ Top ]

addOrder   [line 968]

void addOrder( [string $orderCondition = ''], [boolean $desc = false])

Add a order parameter to the query.
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2003/05/28
  • Access: public

Parameters:

string   $orderCondition   —  the where condition, this can be complete like 'X=7 AND Y=8'
boolean   $desc   —  sorting order (TRUE => ASC, FALSE => DESC)

[ Top ]

addSelect   [line 1304]

void addSelect( [string $what = '*'], [string $connectString = ','])

add a string to the select part of the query

add a string to the select-part of the query and connects it to an existing string using the $connectString, which by default is a comma. (SELECT xxx FROM - xxx is the select-part of a query)

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2003/01/08
  • Access: public

Parameters:

string   $what   —  the string that shall be added to the select-part
string   $connectString   —  the string to connect the new string with the existing one

[ Top ]

addWhere   [line 899]

void addWhere( string $where, [string $condition = 'AND'])

only adds a string to the where clause
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/22
  • Access: public

Parameters:

string   $where   —  the where clause to add to the existing one
string   $condition   —  the condition for how to concatenate the new where clause to the existing one

[ Top ]

addWhereSearch   [line 924]

void addWhereSearch( string $column, string $string, [ $condition = 'AND'])

add a where-like clause which works like a search for the given string

i.e. calling it like this: $this->addWhereSearch('name', 'otto hans') produces a where clause like this one LOWER(name) LIKE "%otto%hans%" so the search finds the given string

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/08/14
  • Access: public

Parameters:

string   $column   —  the column to search in for
string   $string   —  the string to search for
   $condition   — 

[ Top ]

connect   [line 289]

void connect( mixed $dsn, [array $options = array()])

use this method if you want to connect manually

Parameters:

mixed   $dsn   —  DSN string, DSN array or MDB object
array   $options   — 

[ Top ]

debug   [line 1478]

void debug( string $string)

overwrite this method and i.e. print the query $string to see the final query

Parameters:

string   $string   —  the query mostly

[ Top ]

execute   [line 2039]

boolean execute( [string $query = null], [ $method = 'getAll'])

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

string   $query   —  query method
   $method   — 

[ Top ]

get   [line 350]

mixed get( integer $id, [string $column = ''])

get the data of a single entry if the second parameter is only one column the result will be returned directly not as an array!
  • Return: (1) an array of the retrieved data (2) if the second parameter is given and its only one column, only this column's data will be returned (3) false in case of failure
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/03/05
  • Access: public

Parameters:

integer   $id   —  the id of the element to retrieve
string   $column   —  if this is given only one row shall be returned, directly, not an array

[ Top ]

getAll   [line 412]

mixed getAll( [int $from = 0], [int $count = 0], [string $method = 'getAll'])

get all entries from the DB for sorting use setOrder!!!, the last 2 parameters are deprecated
  • Return: an array of the retreived data, or false in case of failure when failing an error is set in $this->_error
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/03/05
  • Access: public

Parameters:

int   $from   —  to start from
int   $count   —  the number of rows to show
string   $method   —  the DB-method to use, i dont know if we should leave this param here ...

[ Top ]

getCol   [line 443]

mixed getCol( [string $column = null], [int $from = 0], [int $count = 0])

this method only returns one column, so the result will be a one dimensional array

this does also mean that using setSelect() should be set to *one* column, the one you want to have returned a most common use case for this could be: $table->setSelect('id'); $ids = $table->getCol(); OR $ids = $table->getCol('id'); so ids will be an array with all the id's

  • Return: an array of the retreived data, or false in case of failure when failing an error is set in $this->_error
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2003/02/25
  • Access: public

Parameters:

string   $column   —  the column that shall be retreived
int   $from   —  to start from
int   $count   —  the number of rows to show

[ Top ]

getCount   [line 471]

mixed getCount( )

get the number of entries
  • Return: an array of the retreived data, or false in case of failure when failing an error is set in $this->_error
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/02
  • Access: public

[ Top ]

getDbInstance   [line 310]

reference &getDbInstance( )

  • Return: to current DB instance

[ Top ]

getDefaultValues   [line 516]

array getDefaultValues( )

return an empty element where all the array elements do already exist corresponding to the columns in the DB
  • Return: an empty, or pre-initialized element
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/05
  • Access: public

[ Top ]

getDontSelect   [line 1342]

string getDontSelect( )


[ Top ]

getEmptyElement   [line 534]

void getEmptyElement( )

this is just for BC
  • Deprecated:

[ Top ]

getGroup   [line 1270]

string getGroup( )

gets the group condition which is used for the current instance
  • Return: the group condition
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/22
  • Access: public

[ Top ]

getHaving   [line 1021]

string getHaving( )

gets the having definition which is used for the current instance
  • Return: the having definition
  • Author: Johannes Schaefer <johnschaefer@gmx.de>
  • Version: 2003/06/05
  • Access: public

[ Top ]

getIndex   [line 2248]

void getIndex( )

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

[ Top ]

getJoin   [line 1148]

array getJoin( [string $what = null])

gets the join-condition
  • Return: gets the join parameters
  • Access: public

Parameters:

string   $what   —  [null|''|'table'|'tables'|'right'|'left']

[ Top ]

getLimit   [line 847]

array getLimit( )


[ Top ]

getMultiple   [line 381]

mixed getMultiple( array $ids, [string $column = ''])

gets the data of the given ids
  • Return: an array of the retreived data, or false in case of failure when failing an error is set in $this->_error
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/23
  • Access: public

Parameters:

array   $ids   —  this is an array of ids to retreive
string   $column   —  the column to search in for

[ Top ]

getOption   [line 1407]

string getOption( $option)


Parameters:

   $option   — 

[ Top ]

getOrder   [line 989]

string getOrder( )

gets the order condition which is used for the current instance
  • Return: the order condition, this can be complete like 'ID,TIMESTAMP DESC'
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/05/16
  • Access: public

[ Top ]

getQueryString   [line 547]

string getQueryString( )

Render the current query and return it as a string.
  • Return: the current query

[ Top ]

getSelect   [line 1320]

string getSelect( )


[ Top ]

getTable   [line 1236]

string getTable( )

gets the table this class is currently working on
  • Return: the table name
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

[ Top ]

getTableShortName   [line 1637]

string getTableShortName( string $table)

this method gets the short name for a table

get the short name for a table, this is needed to properly build the 'AS' parts in the select query

  • Return: the table's short name

Parameters:

string   $table   —  the real table name

[ Top ]

getTableSpec   [line 1663]

array getTableSpec( [array $shortNameIndexed = true], [boolean $tables = array()])

gets the tableSpec either indexed by the short name or the name returns the array for the tables given as parameter or if no parameter given for all tables that exist in the tableSpec
  • Return: the tableSpec indexed

Parameters:

array   $shortNameIndexed   —  table names (not the short names!)
boolean   $tables   —  if true the table is returned indexed by the shortName otherwise indexed by the name

[ Top ]

getWhere   [line 881]

string getWhere( )

gets the where condition which is used for the current instance
  • Return: the where condition, this can be complete like 'X=7 AND Y=8'
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/22
  • Access: public

[ Top ]

metadata   [line 1499]

void metadata( [ $table = ''])

!!!! query COPIED FROM db_oci8.inc - from PHPLIB !!!!
  • Author: PHPLIB
  • Version: 2001/09
  • See:
  • Access: public

Parameters:

   $table   — 

[ Top ]

remove   [line 721]

boolean remove( mixed $data, [string $whereCol = ''])

removes a member from the DB
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/08
  • Access: public

Parameters:

mixed   $data   —  integer/string - the value of the column that shall be removed array - multiple columns that shall be matched, the second parameter will be ignored
string   $whereCol   —  the column to match the data against, only if $data is not an array

[ Top ]

removeAll   [line 759]

void removeAll( )

empty a table
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/06/17
  • Access: public

[ Top ]

removeMultiple   [line 777]

void removeMultiple( array $ids, [ $colName = ''])

remove the datasets with the given ids
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/24
  • Access: public

Parameters:

array   $ids   —  the ids to remove
   $colName   — 

[ Top ]

removePrimary   [line 808]

boolean removePrimary( integer $id, string $colName, object just $atLeastOneObject)

removes a member from the DB and calls the remove methods of the given objects so all rows in another table that refer to this table are erased too
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/08
  • Access: public

Parameters:

integer   $id   —  the value of the primary key
string   $colName   —  the column name of the tables with the foreign keys
object just   $atLeastOneObject   —  for convinience, so nobody forgets to call this method with at least one object as a parameter

[ Top ]

reset   [line 1358]

void reset( [ $what = array()])

reset all the set* settings; with no parameter given, it resets them all
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/09/16
  • Access: public

Parameters:

   $what   — 

[ Top ]

returnResult   [line 2140]

mixed returnResult( object reference &$result)

Return the chosen result type
  • Version: 2004/04/28
  • Access: public

Parameters:

object reference   &$result   — 

[ Top ]

save   [line 576]

mixed save( array $data)

save data, calls either update or add if the primaryCol is given in the data this method knows that the data passed to it are meant to be updated (call 'update'), otherwise it will call the method 'add'.

If you dont like this behaviour simply stick with the methods 'add' and 'update' and ignore this one here. This method is very useful when you have validation checks that have to be done for both adding and updating, then you can simply overwrite this method and do the checks in here, and both cases will be validated first.

  • Return: the data returned by either add or update-method
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/03/11
  • Access: public

Parameters:

array   $data   —  contains the new data that shall be saved in the DB

[ Top ]

setDbInstance   [line 326]

void setDbInstance( object a &$dbh)

Setup using an existing connection.

this also sets the DB_FETCHMODE_ASSOC since this class needs this to be set!


Parameters:

object a   &$dbh   —  reference to an existing DB-object

[ Top ]

setDontSelect   [line 1331]

void setDontSelect( [string $what = ''])


Parameters:

string   $what   — 

[ Top ]

setErrorCallback   [line 2293]

void setErrorCallback( [string $param = ''])

set both callbacks

Parameters:

string   $param   — 

[ Top ]

setErrorLogCallback   [line 2305]

void setErrorLogCallback( [string $param = ''])


Parameters:

string   $param   — 

[ Top ]

setErrorSetCallback   [line 2317]

void setErrorSetCallback( [string $param = ''])


Parameters:

string   $param   — 

[ Top ]

setGroup   [line 1252]

void setGroup( [string $group = ''])

sets the group-by condition
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/22
  • Access: public

Parameters:

string   $group   —  the group condition

[ Top ]

setHaving   [line 1005]

void setHaving( [string $having = ''])

sets the having definition

Parameters:

string   $having   —  the having definition

[ Top ]

setIndex   [line 2218]

void setIndex( [ $key = null])

format the result to be indexed by $key

NOTE: be careful, when using this you should be aware, that if you use an index which's value appears multiple times you may loose data since a key cant exist multiple times!! the result for a result to be indexed by a key(=columnName) (i.e. 'relationtoMe') which's values are 'brother' and 'sister' or alike normally returns this: $res['brother'] = array('name'=>'xxx') $res['sister'] = array('name'=>'xxx') but if the column 'relationtoMe' contains multiple entries for 'brother' then the returned dataset will only contain one brother, since the value from the column 'relationtoMe' is used and which 'brother' you get depends on a lot of things, like the sortorder, how the db saves the data, and whatever else

you can also set indexes which depend on 2 columns, simply pass the parameters like 'table1.id,table2.id' it will be used as a string for indexing the result and the index will be built using the 2 values given, so a possible index might be '1,2' or '2108,29389' this way you can access data which have 2 primary keys. Be sure to remember that the index is a string!

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

   $key   — 

[ Top ]

setJoin   [line 1059]

void setJoin( [mixed $table = null], [string $where = null], [ $joinType = 'default'])

sets a join-condition
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/06/10
  • Access: public

Parameters:

mixed   $table   —  either a string or an array that contains the table(s) to join on the current table
string   $where   —  the where clause for the join
   $joinType   — 

[ Top ]

setLeftJoin   [line 1096]

void setLeftJoin( [string $table = null], [string $where = null])

if you do a left join on $this->table you will get all entries

from $this->table, also if there are no entries for them in the joined table if both parameters are not given the left-join will be removed NOTE: be sure to only use either a right or a left join

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/22
  • Access: public

Parameters:

string   $table   —  the table(s) to be left-joined
string   $where   —  the where clause for the join

[ Top ]

setLimit   [line 832]

void setLimit( [integer $from = 0], [integer $count = 0])


Parameters:

integer   $from   — 
integer   $count   — 

[ Top ]

setOption   [line 1396]

void setOption( string $option, mixed $value)

set mode the class shall work in currently we have the modes: 'raw' does not quote the data before building the query
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/09/17
  • Access: public

Parameters:

string   $option   —  the mode to be set
mixed   $value   —  the value of the mode

[ Top ]

setOrder   [line 951]

void setOrder( [string $orderCondition = ''], [boolean $desc = false])

sets the order condition which is used for the current instance
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/05/16
  • Access: public

Parameters:

string   $orderCondition   —  the where condition, this can be complete like 'X=7 AND Y=8'
boolean   $desc   —  sorting order (TRUE => ASC, FALSE => DESC)

[ Top ]

setRightJoin   [line 1133]

void setRightJoin( [string $table = null], [string $where = null])

see setLeftJoin for further explaination on what a left/right join is NOTE: be sure to only use either a right or a left join

Parameters:

string   $table   —  the table(s) to be right-joined
string   $where   —  the where clause for the join

[ Top ]

setSelect   [line 1282]

void setSelect( [string $what = '*'])

limit the result to return only the columns given in $what

Parameters:

string   $what   —  fields that shall be selected

[ Top ]

setTable   [line 1220]

void setTable( string $table)

sets the table this class is currently working on
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

string   $table   —  the table name

[ Top ]

setWhere   [line 863]

void setWhere( [string $whereCondition = ''])

sets the where condition which is used for the current instance
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/16
  • Access: public

Parameters:

string   $whereCondition   —  the where condition, this can be complete like 'X=7 AND Y=8'

[ Top ]

update   [line 597]

mixed update( array $newData)

update the member data of a data set
  • Return: true on success, or false otherwise
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/03/06
  • Access: public

Parameters:

array   $newData   —  contains the new data that shall be saved in the DB the id has to be given in the field with the key 'ID'

[ Top ]

useResult   [line 2265]

void useResult( [string $type = 'array'])

Choose the type of the returned result
  • Version: 2004/04/28
  • Access: public

Parameters:

string   $type   —  ['array' | 'object' | 'none'] For BC reasons, $type=true is equal to 'array', $type=false is equal to 'none'

[ Top ]

writeLog   [line 2079]

void writeLog( [ $text = 'START'])

Write events to the logfile.

It does some additional work, like time measuring etc. to see some additional info


Parameters:

   $text   — 

[ Top ]

_buildGroup   [line 1903]

string _buildGroup( void 0)

Build the group-clause, replace 'column' by 'table.column'.
  • Return: the rendered group clause
  • Access: public

Parameters:

void   0   — 

[ Top ]

_buildHaving   [line 1926]

string _buildHaving( )

  • Return: the having clause
  • Author: Johannes Schaefer <johnschaefer@gmx.de>
  • Version: 2003/06/05
  • Access: public

[ Top ]

_buildOrder   [line 1881]

void _buildOrder( )

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

[ Top ]

_buildSelect   [line 1690]

string _buildSelect( [string $what = null])

build the 'SELECT <what> FROM ... 'for a select
  • Return: the what-clause
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

string   $what   —  if given use this string

[ Top ]

_buildSelectQuery   [line 1951]

void _buildSelectQuery( [array $query = array()], [boolean $isCalledViaGetCount = false])

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

array   $query   —  this array contains the elements of the query, indexed by their key, which are: 'select','from','where', etc.
boolean   $isCalledViaGetCount   —  whether this method is called via getCount() or not.

[ Top ]

_checkColumns   [line 1443]

void _checkColumns( string $newData, [integer $method = 'unknown'])

checks if the columns which are given as the array's indexes really exist if not it will be unset anyway
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/16
  • Access: public

Parameters:

string   $newData   —  the actual message, first word should always be the method name, to build the message like this: className::methodname
integer   $method   —  the line number

[ Top ]

_errorLog   [line 2336]

void _errorLog( string $msg, [integer $line = 'unknown'])

sets error log and adds additional info
  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/04/16
  • Access: public

Parameters:

string   $msg   —  the actual message, first word should always be the method name, to build the message like this: className::methodname
integer   $line   —  the line number

[ Top ]

_makeIndexed   [line 2167]

mixed &_makeIndexed( mixed &$data)

  • Author: Wolfram Kriesing <wk@visionp.de>
  • Version: 2002/07/11
  • Access: public

Parameters:

mixed   &$data   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:28:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.