| core_db

# Class: Bs_DbWrapper Source Location: /core/db/Bs_DbWrapper.class.php
### Class Overview
    Bs_Object
       |
       --Bs_DbWrapper
DB Wrapper #### Author(s): andrej arn <at blueshoes dot org>, Sam Blum <sam at blueshoes dot org> #### Version: 4.3.$Revision: 1.3 $ $Date: 2003/09/08 17:18:53 $ #### Copyright: blueshoes.org | ### Methods Bs_DbWrapper dbCount dbDelete dbInsert dbUpdate getData getRecordList initByData initByID rlArrayToHashArray setDbName setDbObj setDbTableName sqlArrayToOrderBy sqlPrepareByArray
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 26] DB Wrapper #### Tags:
pattern: | singleton: (pseudostatic)
access: | public
version: | 4.3.$Revision: 1.3 $ $Date: 2003/09/08 17:18:53 $
copyright: | blueshoes.org
author: | andrej arn <at blueshoes dot org>, Sam Blum <sam at blueshoes dot org>
[ Top ] ### Class Methods ### constructor Bs_DbWrapper [line 68]
`Bs_DbWrapper Bs_DbWrapper( )`
constructor [ Top ] ### method dbCount [line 331]
`string dbCount( string $whereCondition, [string $selectAddition = ''])`
If dbCount finds any foreign tables in the where clause then it will put them into a comma separated list. //FROM <tab1>,<tab2> part of the sql query string. param $whereCondition: "WHERE db.table.field = 'foo' AND table.field = 'bar'" param $selectAddition: "db.table.field, table.field, field, " hrm. dunno exactly what's going on here. --andrej #### Tags:
throws: | bool FALSE (not initialized) or bs_exception (db problem/failure)
access: | public
#### Parameters:
string | $whereCondition | (see above)
string | $selectAddition | (see above)
[ Top ] ### method dbDelete [line 249]
`bool dbDelete( )`
Delete the record from the DB. #### Tags:
return: | TRUE
throws: | bool FALSE (not initialized, no data) or bs_exception (db problem/failure)
access: | public
[ Top ] ### method dbInsert [line 209]
`int dbInsert( )`
Insert a new set of data (record) into the DB. It expects the primery Key to be called "ID", which must be temporarly removed to execute the SQL INSERT successfully. Also a field named "timestap" will be temp. removed. #### Tags:
return: | (new record id)
throws: | bool FALSE (not initialized, no data) or bs_exception (db problem/failure)
access: | public
[ Top ] ### method dbUpdate [line 230]
`bool dbUpdate( )`
Replace an existing record or, if not existent, insert a new one. #### Tags:
return: | TRUE
throws: | bool FALSE (not initialized, no data) or bs_exception (db problem/failure)
access: | public
[ Top ] ### method getData [line 131]
`mixed &getData( [string $key = null])`
returns the desirec data. if the param $key is not set or set to null, the whole data array will be returned. you may bet the value by reference. #### Tags:
return: | &(array or string)
see: | var $_recordData
throws: | null on an unknown key. the key is case sensitive.
access: | public
#### Parameters:
string | $key | (default is null. case sensitive.)
[ Top ] ### method getRecordList [line 368]
`array getRecordList( array $fieldArray, [string $whereCondition = ""], string &$orderArray, [int $offset = 0], [int $maxAmount = -1], [mixed $selectAddition = ""])`
//If getRecordList finds any foreign tables in the where clause OR in the fieldArray, it will put it in the the //FROM <tab1>,<tab2> part of the sql query string. #### Tags:
return: | (2d array with the records. output that we got from db->getAll().)
throws: | bool FALSE (not initialized) or bs_exception (db problem/failure)
#### Parameters:
array | $fieldArray | [$fieldArray]; field list, example "firstName", default = select all fields
string | $whereCondition | [$whereCondition]; where conditions, example "WHERE firstName LIKE '%tobler%' AND (ID >= 15 OR someShit = 'hello')",
string | &$orderArray | [$orderArray]; fieldnames for order by, example array("firstName" => "DESC"), default = no order
int | $offset | [$offset]; first record, where to start, example 20, default = no offset
int | $maxAmount | [$maxAmount]; number of records to get, example 50, default = all
[ Top ] ### method initByData [line 191]
`bool initByData( array $data)`
init using the result set (as array). #### Parameters:
array | $data | (hash from db-select => record data.)
[ Top ] ### method initByID [line 178]
`bool initByID( string $id, [string $idFieldName = 'ID'])`
Init by fetching the data from the DB and then call $this->initByData(). #### Tags:
see: | Bs_DbWrapper::initByData()
access: | public
#### Parameters:
string | $id | (the identifier of the table. (The ID field))
string | $idFieldName | (default is 'ID'. if your field is called different, change that.)
[ Top ] ### method rlArrayToHashArray [line 417]
`void rlArrayToHashArray( mixed &$rlArray, [mixed $hashKey = ""])`
[ Top ] ### method setDbName [line 105]
`void setDbName( string $dbName)`
sets the db name that should be used. no check is made if that db exists. #### Tags:
access: | public
#### Parameters:
string | $dbName |
[ Top ] ### method setDbObj [line 80]
`void setDbObj( object &$dbObj)`
sets (overwrites) the db object to use. #### Tags:
access: | public
#### Parameters:
object | &$dbObj | (instance of a subclass of Bs_Db.)
[ Top ] ### method setDbTableName [line 116]
`void setDbTableName( string $tableName)`
sets the table name that should be used. no check is made if that table exists. #### Tags:
access: | public
#### Parameters:
string | $tableName |
[ Top ] ### method sqlArrayToOrderBy [line 515]
`void sqlArrayToOrderBy( array &$theArray)`
Usefull INTELLIGENT helper to built a the ORDER BY postfix sql string. Expects the passed array ($theArray) to be either a normal array of fields or a hash Array of the form array({"fieldName"=>[ "" | "ASC" | "DESC"]}). It will then build the SQL fragment ORDER BY {<field Name> [<order key>]} Examples A Given: array( "name"=>"", "ID"=>"ASC", "time"=>"DESC") Return: " ORDER BY name,ID ASC,time DESC " Examples B Given: array( "name", "ID", "time") Return: " ORDER BY name,ID,time " #### Parameters:
array | $theArray | MAY be either and normal or hash Array. If hash array({"fieldName"=>[ "" | "ASC" | "DESC"]})
[ Top ] ### method sqlPrepareByArray [line 463]
`void sqlPrepareByArray( [string $sqlFormatStr = ""], array &$theArray)`
Usefull INTELLIGENT helper to built a SELECT, INSERT, REPLACE and UPDATE (maybe more) sql string. This fuction expects $sqlFormatStr of th form a) [INSERT | REPLACE | UPDATE] table SET %s [what ever]; b) SELECT %s [what ever]; In case of a) the Array ($theArray) MUST be a hash Array of field value pair. In case of b) the Array ($theArray) MAY be either and normal Array of fields or hash Array of field value pair. See example. #### Tags:
see: | PHP sprintf()
#### Parameters:
string | $sqlFormatStr | : A sql string with 1 (one) %s (string placeholders)
array | $theArray | : Normal or hash array (see above) with dbField and value pair (as given from $this->FArray()) Examples SELECT The Array: array("ID"=>41, "TXT"=>"sample 1", "whatEver"=>"oooo") or: array("ID", "TXT", "whatEver") A) SELECT %s FROM [WHERE where_definition] [LIMIT #] Will return A) SELECT ID,TXT,whatEver FROM [WHERE where_definition] [LIMIT #] Examples INSERT, REPLACE or UPDATE The Array: array("ID"=>41, "TXT"=>"sample 1", "whatEver"=>"oooo") A) UPDATE db.table SET %s [WHERE where_definition] [LIMIT #] B) INSERT [INTO] tbl_name SET %s Will return A) UPDATE db.table SET ID='41',TXT='sample 1',whatEver='oooo' [WHERE where_definition] [LIMIT #]" B) INSERT [INTO] tbl_name SET ID='41',TXT='sample 1',whatEver='oooo'
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:08:47 +0100 by phpDocumentor 1.2.3