Phpfox_Database_Dba

Description

Implements interfaces:

Parent class for all SQL drivers. Each driver needs to interact with this class in case any modifications need to be done to a query.

  • author: Raymond Benc
  • version: $Id: dba.class.php 1687 2010-07-22 03:13:27Z Raymond_Benc $
  • copyright: [PHPFOX_COPYRIGHT]
  • abstract:

Located in /include/library/phpfox/database/dba.class.php (line 19)


	
			
Direct descendents
Class Description
 class Phpfox_Database_Driver_Mysql Database driver for MySQL.
Variable Summary
 array $_aData
 array $_aQuery
 array $_aWords
Method Summary
 Phpfox_Database_Dba __construct ()
 void clean ()
 boolean delete (string $sTable, string $sQuery, [ $iLimit = null])
 void dropTables (string $aDrops, [array $aVals = array()])
 mixed execute ([string $sType = null], [array $aParams = array()])
 object Returns from (string $sTable, [string $sAlias = ''])
 resource getField (string $sSql)
 resource getRow (string $sSql, [bool $bAssoc = true])
 resource getRows (string $sSql, [bool $bAssoc = true])
 resource getSlaveField (string $sSql)
 resource getSlaveRow (string $sSql, [bool $bAssoc = true])
 resource getSlaveRows (string $sSql, [bool $bAssoc = true])
 object Returns group (string $sGroup)
 object Returns having (string $sHaving)
 object Returns innerJoin (string $sTable, string $sAlias, [mixed $mParam = null])
 int insert (string $sTable, [array $aValues = array()], [boolean $bEscape = true], [ $bReturnQuery = false])
 object Returns join (string $sTable, string $sAlias, [mixed $mParam = null])
 object Returns leftJoin (string $sTable, string $sAlias, [mixed $mParam = null])
 object Returns limit (int $iPage, [string $sLimit = null], [int $iCnt = null])
 int multiInsert (string $sTable, array $aFields, array $aValues)
 object Returns order (string $sOrder)
 object Returns process (array $aFields, array $aVals)
 object Returns select (string $sSelect)
 boolean update (string $sTable, [array $aValues = array()], [string $sCond = null], [boolean $bEscape = true])
 void updateCount (string $sCountTable, array $aCountCond, string $sCounter, string $sUpdateTable, array $aUpdateCond)
 void updateCounter (string $sTable, string $sCounter, string $sField, int $iId, [bool $bMinus = false])
 object Returns where (mixed $aConds)
 mixed _getField (string $sSql,  &$hLink, resource $hLink)
 string _insert (string $sTable, string $sFields, string $sValues)
 void _join (string $sType, string $sTable, string $sAlias, [mixed $mParam = null])
 string _update (string $sTable, string $sSets, string $sCond)
Variables
array $_aData = array() (line 44)

Holds all the data that has been filtered when inserting or updating information directly from a from posted by an end user.

  • access: private
array $_aQuery = array() (line 27)

Array of all the parts of a query we are going to execute

  • see: self::execute()
  • access: protected
array $_aWords = array() (line 36)

Array of all the words that cannot be used when creating a database table or field. This is only used in development mode.

  • access: protected
Methods
Constructor __construct (line 51)

Class constructor. If we are in development mode we store all the words that cannot be used when creating tables or fields.

  • access: public
Phpfox_Database_Dba __construct ()
clean (line 472)

We clean out the query we just ran so another query can be built

  • access: public
void clean ()
delete (line 651)

Delete entry from the database

  • return: true - update successfule, false - error
  • access: public
boolean delete (string $sTable, string $sQuery, [ $iLimit = null])
  • string $sTable: is the table name
  • string $sQuery: is the query we will run
  • $iLimit
dropTables (line 667)

Drops tables from the database

  • access: public
void dropTables (string $aDrops, [array $aVals = array()])
  • string $aDrops: Array of tables to drop
  • array $aVals: Not being used at the moment.
execute (line 389)

Performs the final SQL query with all the information we have gathered from various other methods in this class. Via this method you can perform all tasks from getting a single field from a row, to just one row or a list of rows.

  • return: Depending on the command you ran this can return various things, usually an array but it all depends on what you executed.
  • see: self::getField()
  • see: self::getRows()
  • see: self::getRow()
  • access: public
mixed execute ([string $sType = null], [array $aParams = array()])
  • string $sType: The command we plan to execute. It can also be NULL or empty and will simply return the SQL query itself without executing it.
  • array $aParams: Any special commands that we need to run can be passed here. Mainly used if we were to cache the actual query.
from (line 224)

Stores the FROM part of a query

  • return: own object
  • see: self::execute()
  • access: public
object Returns from (string $sTable, [string $sAlias = ''])
  • string $sTable: Table to query
  • string $sAlias: Optional usage of alias can be passed here
getField (line 152)

Returns one field from a row

  • return: SQL resource
  • access: public
resource getField (string $sSql)
  • string $sSql: SQL query
getRow (line 129)

Returns one row

  • return: SQL resource
  • access: public
resource getRow (string $sSql, [bool $bAssoc = true])
  • string $sSql: SQL query
  • bool $bAssoc: True to return an associative array
getRows (line 141)

Returns several rows

  • return: SQL resource
  • access: public
resource getRows (string $sSql, [bool $bAssoc = true])
  • string $sSql: SQL query
  • bool $bAssoc: True to return an associative array
getSlaveField (line 87)

Returns one field from a row using a slave connection

  • return: SQL resource
  • access: public
resource getSlaveField (string $sSql)
  • string $sSql: SQL query
getSlaveRow (line 101)

Returns one row using a slave connection

  • return: SQL resource
  • access: public
resource getSlaveRow (string $sSql, [bool $bAssoc = true])
  • string $sSql: SQL query
  • bool $bAssoc: True to return an associative array
getSlaveRows (line 115)

Returns several rows using a slave connection

  • return: SQL resource
  • access: public
resource getSlaveRows (string $sSql, [bool $bAssoc = true])
  • string $sSql: SQL query
  • bool $bAssoc: True to return an associative array
group (line 260)

Stores the GROUP BY part of a query

  • return: own object
  • see: self::execute()
  • access: public
object Returns group (string $sGroup)
  • string $sGroup: SQL GROUP BY command
having (line 274)

Stores the HAVING part of a query

  • return: own object
  • see: self::execute()
  • access: public
object Returns having (string $sHaving)
  • string $sHaving: SQL HAVING command
innerJoin (line 320)

Creates a INNER JOIN for an SQL query.

Example of left joining tables:

  1.  Phpfox::getLib('database')->select('*')
  2.          ->from('user''u')
  3.          ->innerJoin('user_info''ui''ui.user_id = u.user_id')
  4.          ->execute('getRows');

  • return: own object
  • see: self::_join()
  • access: public
object Returns innerJoin (string $sTable, string $sAlias, [mixed $mParam = null])
  • string $sTable: Table to join
  • string $sAlias: Alias to use to identify the table and make it unique
  • mixed $mParam: Can be a string or an array of how to link the tables. This is usually a string that contains the part found with an SQL ON(__STRING__)
insert (line 528)

Performs insert of one row. Accepts values to insert as an array: 'column1' => 'value1' 'column2' => 'value2'

  • return: last ID (or 0 on error)
  • access: public
int insert (string $sTable, [array $aValues = array()], [boolean $bEscape = true], [ $bReturnQuery = false])
  • string $sTable: table name
  • array $aValues: column and values to insert
  • boolean $bEscape: true - method escapes values (with "), false - not escapes
  • $bReturnQuery
join (line 343)

Creates a JOIN for an SQL query.

Example of left joining tables:

  1.  Phpfox::getLib('database')->select('*')
  2.          ->from('user''u')
  3.          ->join('user_info''ui''ui.user_id = u.user_id')
  4.          ->execute('getRows');

  • return: own object
  • see: self::_join()
  • access: public
object Returns join (string $sTable, string $sAlias, [mixed $mParam = null])
  • string $sTable: Table to join
  • string $sAlias: Alias to use to identify the table and make it unique
  • mixed $mParam: Can be a string or an array of how to link the tables. This is usually a string that contains the part found with an SQL ON(__STRING__)
leftJoin (line 297)

Creates a LEFT JOIN for an SQL query.

Example of left joining tables:

  1.  Phpfox::getLib('database')->select('*')
  2.          ->from('user''u')
  3.          ->leftJoin('user_info''ui''ui.user_id = u.user_id')
  4.          ->execute('getRows');

  • return: own object
  • see: self::_join()
  • access: public
object Returns leftJoin (string $sTable, string $sAlias, [mixed $mParam = null])
  • string $sTable: Table to join
  • string $sAlias: Alias to use to identify the table and make it unique
  • mixed $mParam: Can be a string or an array of how to link the tables. This is usually a string that contains the part found with an SQL ON(__STRING__)
limit (line 361)

Stores the LIMIT/OFFSET part of a query. It can also be used to create a pagination if params 2 and 3 and filled otherwise it bahaves just as a limit on the SQL query.

  • return: own object
  • see: self::execute()
  • access: public
object Returns limit (int $iPage, [string $sLimit = null], [int $iCnt = null])
  • int $iPage: If $sLimit and $iCnt are NULL then this value is the LIMIT on the SQL query. However if $sLimit and $iCnt are not NULL then this value is the current page we are on.
  • string $sLimit: Is how many to limit per query
  • int $iCnt: Is how many rows there are in this query
multiInsert (line 578)

Runs an SQL query to run one SQL query and insert multiple rows. The 2nd and 3rd params much match in order to inser the data correctly.

  • return: Returns the last ID of the insert. Usually the auto_increment.
  • access: public
int multiInsert (string $sTable, array $aFields, array $aValues)
  • string $sTable: Table to insert the data
  • array $aFields: Array of table fields
  • array $aValues: Array of values to insert that matches the table fields
order (line 243)

Stores the ORDER part of a query

  • return: own object
  • see: self::execute()
  • access: public
object Returns order (string $sOrder)
  • string $sOrder: SQL ORDER BY command
process (line 484)

Process data from a form a end-user posted and prepare it to be used when inserting/updating records

  • return: own object
  • access: public
object Returns process (array $aFields, array $aVals)
  • array $aFields: Array of rules of the fields that are allowed and the type it must be
  • array $aVals: $_POST fields from a form
select (line 164)

Stores the SELECT part of a query

  • return: own object
  • see: self::execute()
  • access: public
object Returns select (string $sSelect)
  • string $sSelect: Select part of an SQL query
update (line 618)

Performs update of rows.

  • return: true - update successfule, false - error
  • access: public
boolean update (string $sTable, [array $aValues = array()], [string $sCond = null], [boolean $bEscape = true])
  • string $sTable: table name
  • array $aValues: array of column=>new_value
  • string $sCond: condition (without WHERE)
  • boolean $bEscape: true - method escapes values (with "), false - not escapes
updateCount (line 712)

This in practice works similar to our previous method self::updateCounter(), however instead of increasing or decreasing a field it checks the table to see how many rows there are and updates the static field with that count. This is usually only used in the AdminCP to fix broken counters.

  • access: public
void updateCount (string $sCountTable, array $aCountCond, string $sCounter, string $sUpdateTable, array $aUpdateCond)
  • string $sCountTable: Table to check how many rows there are
  • array $aCountCond: SQL conditional statement for the table we are checking
  • string $sCounter: Field name of the table we are updating the static count
  • string $sUpdateTable: Table we are going to be updating with the new count number
  • array $aUpdateCond: SQL conditional statment for the table we are updating
updateCounter (line 693)

Updates a int field in the database to increase or decrease its count.

We usually use this to cache information about a user. Lets take for example a user has 10 friends and instead of running a query to the database to check how many friends they have we just store a static count in the database. So when they add or remove a friend we then either increase or decrease the static record.

Example:

  1.  Phpfox::getLib('database')->updateCounter('user_count''total_friend''user_id'1);

  • access: public
void updateCounter (string $sTable, string $sCounter, string $sField, int $iId, [bool $bMinus = false])
  • string $sTable: Table to update
  • string $sCounter: Field we are going to be updating. This is where the static value is
  • string $sField: Field we need to identify the record we are going to be updating
  • int $iId: ID of the field we are going to be updating
  • bool $bMinus: False by default as we usually increase a count, if we decrease a count set this to true
where (line 194)

Stores the WHERE part of a query

Example using a string method:

  1.  ->where('user_id = 1')
Example using an array method:
  1.  $aCond array();
  2.  $aCond['AND user_id = 1';
  3.  $aCond['AND email = \'foo@bar.com\'';
  4.  ->where($aCond)

  • return: own object
  • see: self::execute()
  • access: public
object Returns where (mixed $aConds)
  • mixed $aConds: Can be a string of the WHERE part of an SQL query or an array or all the parts of an SQL query.
_getField (line 803)

Returns one field from a row

  • return: field value
  • access: private
mixed _getField (string $sSql,  &$hLink, resource $hLink)
  • string $sSql: SQL query
  • resource $hLink: SQL resource
  • &$hLink
_insert (line 776)

Insert data into the database

  • return: Returns the actual SQL query to perform
  • access: protected
string _insert (string $sTable, string $sFields, string $sValues)
  • string $sTable: Database table
  • string $sFields: List of fields
  • string $sValues: List of values
_join (line 733)

Performs all the joins based on information passed from JOIN methods within this class.

  • see: self::innerJoin()
  • see: self::leftJoin()
  • see: self::join()
  • access: protected
void _join (string $sType, string $sTable, string $sAlias, [mixed $mParam = null])
  • string $sType: The type of join we are going to use (LEFT JOIN, JOIN, INNER JOIM)
  • string $sTable: Table to join
  • string $sAlias: Alias to use to identify the table and make it unique
  • mixed $mParam: Can be a string or an array of how to link the tables. This is usually a string that contains the part found with an SQL ON(__STRING__)
_update (line 791)

Updates data in a specific table

  • return: Returns the actual SQL query to perform
  • access: protected
string _update (string $sTable, string $sSets, string $sCond)
  • string $sTable: Table we are updating
  • string $sSets: SQL SET command
  • string $sCond: SQL WHERE command

Documentation generated on Tue, 28 Sep 2010 10:36:38 +0200 by phpDocumentor 1.4.0a2