| core_db

# Class: Bs_Db Source Location: /core/db/Bs_Db.class.php
### Class Overview
    Bs_Object
       |
       --Bs_Db
abstract class Bs_Db.class.php #### Author(s): andrej arn <at blueshoes dot org> #### Version: 4.0.$Revision: 1.6 $ #### Copyright: blueshoes | ### Variables $Bs_Date $format | ### Methods Bs_Db affectedRows assertExtension autoCommit commit countRead countWrite dbPing escapeString fetchRow formatDateForDb formatDatetimeForDb formatTimestampForDb freeResult getAll getAssoc getAssoc2 getAssoc3 getCol getDsn getErrorMessage getFieldValue getNumRecords getOne getRow idWrite insertId isManipulation nativeErrorCode nativeErrorMsg numCols numRows parseDsn provides quoteArgs read rollback rsRead setPointer startTransaction toString write
### Child classes: Bs_MsSql This is the API for MSSQL it's an extention of the abstract class Bs_Db.class.php Bs_MySql This is the API for mySQL it's an extention of the abstract class Bs_Db.class.php Bs_Oci *********************************************************************** This is the API for Oracle. it's an extention of the abstract class Bs_Db.class.php Bs_Odbc *********************************************************************** dependencies: Bs_Db | ### 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 140] abstract class Bs_Db.class.php This object is the abstract layer for Db access. It holds the basic fuctions that are DB-independent. To makes use of this object, you must extend it to a DB-specific object like Bs_MySql.class.php. Some collected knowledge: Watch out when you make queries based on variables from a surfer. "SELECT * FROM table where ID=$ID" can easily be hacked to empty your table. Parse all variables submitted through forms/get if they are to be used in any similar situation. Of course, the hacker would need to know the name of your table. In some dbms like MS-ACCESS and mssql (if you call them dbms :) can have field names with spaces. A query would look like this "SELECT [fieldname withspace], anotherField FROM tbl". Please *NEVER* ever use that 'feature'. Many dbms don't support it (like mySQL); it's ugly and screams for probs. dependencies: Bs_System, Bs_Date #### Tags:
access: | public
pattern: | singleton: (pseudostatic)
abstract: |
version: | 4.0.$Revision: 1.6 $
author: | andrej arn <at blueshoes dot org>
copyright: | blueshoes
[ Top ] ### Class Variables #### $Bs_Date = [line 193] reference to the globally used pseudostatic Bs_Date object. #### Tags:
access: | public
Type: | object
[ Top ] #### $format = array( 'date' => "'Y-m-d'", 'datetime' => "'Y-m-d H:i:s'", 'timestamp' => "'YmdHis'", ) [line 228] some database specific formats. please overwrite. #### Tags:
see: | Bs_Db::formatDateForDb(), Bs_Db::formatDatetimeForDb(), Bs_Db::formatTimestampForDb()
access: | public
Type: | array
[ Top ] ### Class Methods ### constructor Bs_Db [line 238]
`Bs_Db Bs_Db( )`
constructor. [ Top ] ### method affectedRows [line 1343]
`int affectedRows( )`
Gets the number of rows affected by the last data manipulation query. #### Tags:
return: | see above
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::affectedRows() Gets the number of rows affected by the data manipulation query. Bs_MySql::affectedRows() Gets the number of rows affected by the data manipulation query. Bs_Oci::affectedRows() Gets the number of rows affected by the data manipulation query. [ Top ] ### method assertExtension [line 1012]
`bool assertExtension( $name $name)`
Load a PHP database extension if it is not loaded already. #### Tags:
return: | true if the extension was already or successfully loaded, false if it could not be loaded
todo: | take care, php's dl() function has been deprecated and is likely to be removed in php 4.1 or 5.
access: | public
#### Parameters:
$name | $name | the DB base name of the extension (without the .so or .dll suffix)
[ Top ] ### method autoCommit [line 1244]
`last autoCommit( [bool $on = FALSE])`
Turn autoCommit on or off #### Tags:
return: | state: TRUE if it was on; FALSE if it was off.
throws: | Bs_Exception if not supported by this DB
access: | public
Overridden in child classes as: Bs_MsSql::autoCommit() Turn autoCommit on or off Bs_MySql::autoCommit() Turn autoCommit on or off #### Parameters:
bool | $on | (opt) If TRUE turn on else off (default TRUE)
[ Top ] ### method commit [line 1264]
`TRUE commit( )`
Commit last query #### Tags:
return: | on success.
throws: | Bs_Exception if not supported by this DB or on any other error.
access: | public
Overridden in child classes as: Bs_MsSql::commit() Commit the current or given transaction. Bs_MySql::commit() Commit the current or given transaction. [ Top ] ### method countRead [line 429]
`int countRead( string $query)`
Issue a select query and return the number of 'affected' rows. This method makes use of this->numRows(). #### Tags:
return: | number of rows matched (0-x)
todo: | we could optimize this, modifying the query to do "SELECT COUNT(*)".
see: | Bs_Db::read(), Bs_Db::rsRead()
throws: | Bs_Exception
access: | public
#### Parameters:
string | $query | A SQL statement.
[ Top ] ### method countWrite [line 483]
`int countWrite( string $query)`
Issue a write query (update, delete, replace) and return the number of affected rows. this method makes use of this->affectedRows() read the doc of it! #### Tags:
return: | number of rows affected
see: | Bs_Db::affectedRows()
see: | Bs_Db::write(), Bs_Db::idWrite()
throws: | Bs_Exception if the query was unsuccessful, FALSE if the count with affectedRows() failed.
access: | public
#### Parameters:
string | $query | A modifing SQL statement.
[ Top ] ### method dbPing [line 250]
`boolean dbPing( )`
Tells whether we're connected. #### Tags:
return: | TRUE if connected, else FALSE
access: | public
[ Top ] ### method escapeString [line 1049]
`string escapeString( string $query)`
Escape string for the query. if there is a better/specialized way for your specific rdbms, overwrite this. #### Tags:
return: | the escaped query
Overridden in child classes as: Bs_MsSql::escapeString() Escape string for mssql query. Bs_MySql::escapeString() Escape string for mysql query. Bs_Oci::escapeString() Escape string for oracle query. Bs_Odbc::escapeString() Escape string for mysql query. #### Parameters:
string | $query |
[ Top ] ### method fetchRow [line 1302]
`mixed fetchRow( $result $result, [$fetchMode $fetchMode = BS_DB_FETCHMODE_ASSOC])`
Fetch a row and return it as vector or hash depending on the fetchMode. Subsequent calls will return the next row in the result set, or NULL if there are no more rows. If fetchMode is BS_DB_FETCHMODE_ASSOC (default) it returns a hash array that corresponds to the fetched row else if it's BS_DB_FETCHMODE_ORDERED returns a vector starting at offset 0. #### Tags:
return: | vector, hash or NULL if there is no more data
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::fetchRow() Fetch a row and return it as vector or hash depending on the fetchMode. Bs_MySql::fetchRow() Fetch a row and return it as vector or hash depending on the fetchMode. Bs_Oci::fetchRow() Fetch a row and return it as vector or hash depending on the fetchMode. Bs_Odbc::fetchRow() Fetch a row and return it as vector or hash depending on the fetchMode. #### Parameters:
$result | $result | result identifier
$fetchMode | $fetchMode | (opt) (default BS_DB_FETCHMODE_ASSOC) see above.
[ Top ] ### method formatDateForDb [line 1062]
`string formatDateForDb( string $date)`
format and return date string in database date format. overwrite this if needed. #### Tags:
return: | (date formatted for this rdbms implementation)
see: | Bs_Db::formatDatetimeForDb(), Bs_Db::formatTimestampForDb()
Overridden in child classes as: Bs_Oci::formatDateForDb() format and return date string in database date format. #### Parameters:
string | $date | (yyyy-mm-dd)
[ Top ] ### method formatDatetimeForDb [line 1075]
`string formatDatetimeForDb( string $datetime)`
format and return datetime string in database datetime format. overwrite this if needed. #### Tags:
return: | (datetime formatted for this rdbms implementation)
see: | Bs_Db::formatDateForDb(), Bs_Db::formatTimestampForDb()
Overridden in child classes as: Bs_Oci::formatDatetimeForDb() format and return datetime string in database datetime format. #### Parameters:
string | $datetime | (yyyy-mm-dd hh:mm:ss)
[ Top ] ### method formatTimestampForDb [line 1088]
`string formatTimestampForDb( mixed $timestamp, string $datetime)`
format and return timestamp string in database timestamp format. overwrite this if needed. #### Tags:
return: | (timestamp formatted for this rdbms implementation)
see: | Bs_Db::formatDateForDb(), Bs_Db::formatDatetimeForDb()
Overridden in child classes as: Bs_Oci::formatTimestampForDb() format and return timestamp string in database timestamp format. #### Parameters:
string | $datetime | (yyyy-mm-dd hh:mm:ss)
[ Top ] ### method freeResult [line 1311]
`void freeResult( $result $result)`
Free the internal resources associated with $result. #### Tags:
access: | public
Overridden in child classes as: Bs_MsSql::freeResult() Free the internal resources associated with $result. Only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. Bs_MySql::freeResult() Free the internal resources associated with $result. Only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. Bs_Oci::freeResult() Free the internal resources associated with $result. Only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. Bs_Odbc::freeResult() Free the internal resources associated with $result. Only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. #### Parameters:
$result | $result | result identifier or DB statement identifier
[ Top ] ### method getAll [line 978]
`array &getAll( mixed $source, [int $fetchMode = BS_DB_FETCHMODE_ASSOC])`
Fetch the entire data given by the param $source into a hash. $source can be either a SQL query string or a result set. IF param $source is a query-string: Execute the query, fetch entire data and clean up (free the results set). ELSEIF param $source is a result set: Fetch the entire data. Don't free result set. Sample: Given is the table "mytable" containing: ID TEXT DATE ------------------------------- 'one' 09.05.1960 'two' 25.12.1970 'three' 31.01.1980 getAll('SELECT id, teXt, date as birthday FROM mydate', 'teXt', BS_DB_FETCHMODE_ASSOC) returns: would return: array( array('id' => '1', 'teXt' => 'one', 'birthday' => '09.05.1960'), array('id' => '2', 'teXt' => 'two', 'birthday' => '25.12.1970'), array('id' => '3', 'teXt' => 'three', 'birthday' => '31.01.1980') ) #### Tags:
return: | a nested array. See sample above. may be an empty array if nothing was found.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
int | $fetchMode | (opt) (default BS_DB_FETCHMODE_ASSOC) see getRow.
[ Top ] ### method getAssoc [line 751]
`hash &getAssoc( mixed $source, [bool $forceArray = FALSE], [bool $hashInsteadOfVector = FALSE])`
Fetch the entire data given by the param $source into a hash using the first column as the key. $source can be either a SQL query string or a result set. IF param $source is a query-string: Execute the query, fetch entire data and clean up (free the results set). ELSEIF param $source is a result set: Fetch the entire data. Don't free result set. If more than 2 values are involved in the result set or if $forceArray is TRUE, a hash containing a vector is returned e.g. array('1' => array('one', '944679408')); otherwise a simple hash is returned (see sample below). If the result set contains fewer than two columns, a BS_DB_ERROR_TRUNCATED exception is raised. Sample: Given is the table "mytable" containing: ID TEXT DATE ------------------------------- 'one' 09.05.1960 'two' 25.12.1970 'three' 31.01.1980 example 1: getAssoc('SELECT id,text FROM mytable'); // would return: array( '1' => 'one', '2' => 'two', '3' => 'three' ) example 2: getAssoc('SELECT id,text,date FROM mydate') // would return: array( '1' => array('one', '944679408'), '2' => array('two', '944679408'), '3' => array('three', '944679408') ) example 3: getAssoc('SELECT id,text,date FROM mydate', TRUE, TRUE) // would return: array( '1' => array('text'=>'one', 'date'=>'944679408'), '2' => array('text'=>'two', 'date'=>'944679408'), '3' => array('text'=>'three', 'date'=>'944679408') ) this option is new, 2002/03/25 --andrej special note: you have to use a key that is unique. otherwise only one record will be used, i think the later ones overwrite the previews. #### Tags:
return: | with first col value as key and the rest as vector.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
bool | $forceArray | (opt) 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.
bool | $hashInsteadOfVector | (default is FALSE. if set to true then the values will be returned in a hash (with field names) instead of a vector. see example 3 above.)
[ Top ] ### method getAssoc2 [line 841]
`hash &getAssoc2( mixed $source, [bool $forceArray = FALSE])`
hash array COLUMN BY COLUMN not record by record. The rest is like getAssoc(). See above. Sample: Given is the table "mytable" containing: ID TEXT DATE ------------------------------- 'one' 09.05.1960 'two' 25.12.1970 'three' 31.01.1980 getAssoc2('SELECT id, teXt, date as birthday FROM mytable'); would return: array( 'id' => array('1', '2', '3'), 'teXt' => array('one', 'two', 'three'), 'birthday' => array('09.05.1960', '25.12.1970', '31.01.1980') ) #### Tags:
return: | with field names as key and the rest as vector.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
bool | $forceArray | used only when the query returns exactly 1 column. If true, the values of the returned array will be one-element arrays instead of scalars.
[ Top ] ### method getAssoc3 [line 913]
`hash &getAssoc3( mixed $source)`
group the values of one field by another one. see the example. Sample: Given is the table "mytable" containing: ID aID bID -------------------------- 2 1 2 2 2 3 5 1 5 2 6 3 getAssoc3('SELECT aID, bID FROM mytable'); would return: array( '2' => array('1', '2', '3'), '5' => array('1', '2'), '6' => array('3'), ) you have to select exactly 2 fields. not less, not more. #### Tags:
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
[ Top ] ### method getCol [line 667]
`vector &getCol( mixed $source, [mixed $col = 0], [int $startRow = 0], [int $amount = -1])`
Fetch a full OR fraction col of data as vector given by the param $source. IF param $source is a query-string: Execute the query, fetch col and clean up (free the results set). ELSEIF param $source is a result set: Move down $row-rows, fetch col and leave DB curser *after* last read row. Don't free result set. NOTE: col may be given as col-name (string) instead of offset (int). It will be used as key to identify the right column. So pass the right type! Sample: Given is the table "mytable" containing: \/ ID TEXT DATE ------------------------------- 'one' 09.05.1960 'two' 25.12.1970 'three' 31.01.1980 /\ getCol('SELECT id, teXt, date as birthday FROM mydate', 'teXt'); // would return array('one', 'two', 'three'); If you'd only wand to get array('two', 'three') you'd do: getCol($query, 1, 1) or getCol($query, 1, 1, 2) or getCol($query, 'teXt', 1) #### Tags:
return: | of col values (vector of NULLs if col is out of bounds) or NULL $amount=0 or if $startRow is out of bounds.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
mixed | $col | which column to return (integer [column number, starting at 0] or string [column name])
int | $startRow | the row number at which we start, *including* that row. default is 0.
int | $amount | the row number at which we stop, *including* that row. default is -1 which means loop until the end.
[ Top ] ### method getDsn [line 262]
`mixed &getDsn( [string $key = NULL])`
Return the _dsnInfo-hash. #### Tags:
return: | (&hash return the _dsnInfo-hash or mixed, depending on param $key.)
see: | var _dsnInfo.
access: | public
#### Parameters:
string | $key | if specified then only the value for the given key will be returned.
[ Top ] ### method getErrorMessage [line 1173]
`string getErrorMessage( long $errCode)`
Return a textual error message for a bs DB error code #### Tags:
return: | error message, or false if the error code was not recognized
#### Parameters:
long | $errCode | a bs error code (see constants)
[ Top ] ### method getFieldValue [line 358]
`mixed getFieldValue( string $theTable, string $fieldToSearch, string $valueToSearch, mixed $fieldToGet, [bool $caseSensitive = TRUE])`
Returns 1-n db-field values. Example I: $birthday = getFieldValue($theTable='employees', $fieldToSearch='username', $valueToSearch='Hugentobler', $fieldToGet='birthday') Example II: list($birthday, $phone) = getFieldValue('employees', 'username', 'Hugentobler', array('birthday', 'phone')) NOTE: Only the first found record is used. #### Tags:
return: | The desired field value, whatever that is. If param $fieldToGet is an array, an array is returned here.
throws: | bs_exception
access: | public
#### Parameters:
string | $theTable | The db-table to search. Can also be 'database.table'.
string | $fieldToSearch | The field to compare.
string | $valueToSearch | The value to compare.
mixed | $fieldToGet | The field name as string of which we want the value, or an array with field names.
bool | $caseSensitive | (opt) if the compare in the db should be made case sensitive or no. default is TRUE.
[ Top ] ### method getNumRecords [line 309]
`int getNumRecords( string $query, [bool $ignoreLimit = TRUE])`
Returns the number of records that get selected for a given query. Example: You want to display page 5 of your search engine with 10 results (per page). So your query would look like this: "select * from searchEngine limit 40,10". But at the same time, you want to show the user how many records really *were* found. The numRows() for the above query will only show you 10... Caution: Never fire a delete statement to this method. This is for select queries only. If you do and it has a 'limit' clause and $ignoreLimit is set to true, the limit will be ignored... NOTE: since bs-4.5 this is optimized. "select x, y from table" is replaced with "select count(*) from table", and if there is a "limit x, y" clause, it is removed. the first part has been added in bs-4.5. #### Tags:
return: | the number of records
throws: | Bs_Exception
#### Parameters:
string | $query |
bool | $ignoreLimit | (opt) Default TRUE. If TRUE, a limit x,y in the given query is ignored.
[ Top ] ### method getOne [line 549]
`mixed &getOne( mixed $source, [int $row = 0], [mixed $col = 0])`
Fetch a single value from a data amount given by the param $source. $source can be either a SQL query string or a result set. IF param $source is a query-string: Execute the query, fetch value and clean up (free the results set). ELSEIF param $source is a result set: Move down $row-rows, fetch value at $col and leave DB curser *after* offset rows. Don't free result set. A row and col offset can be given. Top left cell is row=0 / col=0. The default behavior is to fetch cell [0,0] (top left cell). NOTE: col may be given as col-name (string) instead of offset (int). It will be used as key to identify the right column. So pass the right type! Sample: Given is the table "mytable" containing: \/ ID TEXT DATE ------------------------------- -> 1 'one' 09.05.1960 2 'two' 25.12.1970 3 'three' 31.01.1980 getOne('SELECT id, teXt, date as birthday FROM mytable'); // would return '1'. getOne($query, 1, 2); // would return '25.12.1970'. getOne($query, 2, 'teXt'); // would return 'two'. #### Tags:
return: | just one value or NULL if row or col are out of bounds or don't exsist.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query as string, or a result set (a resource).
int | $row | the row number
mixed | $col | which column to return (integer [column number, starting at 0] or string [column name])
[ Top ] ### method getRow [line 609]
`mixed &getRow( mixed $source, [int $row = -1], [int $fetchMode = BS_DB_FETCHMODE_ASSOC])`
Fetch a full row of data as vector or hash given by the param $source. $source can be either a SQL query string or a result set. If fetchMode is BS_DB_FETCHMODE_ASSOC (default) returns a hash array that corresponds to the fetched row else if it's BS_DB_FETCHMODE_ORDERED returns a vector starting at offset 0. IF param $source is a query-string: Execute the query, fetch row and clean up (free the results set). ELSEIF param $source is a result set: Move down $row-rows, fetch row and leave DB curser *after* offset rows. Don't free result set. The default behaver is to fetch current row. Sample: Given is the table "mytable" containing: ID TEXT DATE ------------------------------- -> 1 'one' 09.05.1960 <- 2 'two' 25.12.1970 3 'three' 31.01.1980 getRow('SELECT id, teXt, date as birthday FROM mydate'); // would return array('id' => '1', 'teXt' => 'one', 'birthday' => '09.05.1960'); #### Tags:
return: | vector, hash. NULL if row offest is out of bounds OR no data found.
throws: | Bs_Exception on error
access: | public
#### Parameters:
mixed | $source | can be an SQL query string, or a resource.
int | $row | IF >=0 will move internal row pointer to abs. position befor fetching the data. Default is -1.
int | $fetchMode | (opt) (default BS_DB_FETCHMODE_ASSOC) see above.
[ Top ] ### method idWrite [line 504]
`int idWrite( string $query)`
Issue an insert query on a table with an auto_increment field and return the newly inserted id. this method makes use of this->insertId() read the doc of it! #### Tags:
return: | >=1
see: | Bs_Db::countWrite(), Bs_Db::write(), Bs_Db::insertId()
throws: | Bs_Exception if the query failed, FALSE if the operation was not an insert.
access: | public
Overridden in child classes as: Bs_Oci::idWrite() overwrites parent method. #### Parameters:
string | $query | A SQL statement that inserts a record.
[ Top ] ### method insertId [line 1353]
`int insertId( )`
Get the id generated from the previous INSERT operation. #### Tags:
return: | a positive integer, which means >=1
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::insertId() Returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query on this thread. Bs_MySql::insertId() Returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query on this thread. Bs_Oci::insertId() [ Top ] ### method isManipulation [line 1139]
`one isManipulation( string $query)`
Tells whether a query is a data manipulation query (insert, update, delete replace, alter, drop, create). #### Tags:
return: | of (INSERT|UPDATE|DELETE|REPLACE|ALTER|DROP|CREATE) if found; else FALSE.
#### Parameters:
string | $query | the query
[ Top ] ### method nativeErrorCode [line 1363]
`int nativeErrorCode( )`
Returns the numerical native error code from the previous DB operation or 0 (zero) if no error occured. #### Tags:
return: | see above
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MySql::nativeErrorCode() Returns the numerical native error code from the previous MySQL operation or 0 (zero) if no error occured. Bs_Oci::nativeErrorCode() Returns the numerical native error code from the previous sql operation or 0 (zero) if no error occured. Bs_Odbc::nativeErrorCode() Returns the numerical native error code from the previous db operation or 0 (zero) if no error occured. [ Top ] ### method nativeErrorMsg [line 1373]
`string nativeErrorMsg( )`
Returns the native error text from the previous DB operation or '' (empty string) if no error occured. #### Tags:
return: | see above
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::nativeErrorMsg() Returns the native error text from the previous MsSQL operation or '' (empty string) if no error occured or the error was below the min_message_severity. Bs_MySql::nativeErrorMsg() Returns the native error text from the previous MySQL operation or '' (empty string) if no error occured. Bs_Oci::nativeErrorMsg() Returns the native error text from the previous sql operation or '' (empty string) if no error occured. Bs_Odbc::nativeErrorMsg() Returns the native error text from the previous db operation or '' (empty string) if no error occured. [ Top ] ### method numCols [line 1322]
`int numCols( $result $result)`
Get the number of columns (fields) in a result identifier. #### Tags:
return: | the number of columns per row in $result
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::numCols() Get the number of columns (fields) from a result set. Bs_MySql::numCols() Get the number of columns (fields) from a result set. Bs_Oci::numCols() Get the number of columns (fields) from a result set. Bs_Odbc::numCols() Get the number of columns (fields) from a result set. #### Parameters:
$result | $result | result identifier
[ Top ] ### method numRows [line 1333]
`int numRows( $result $result)`
Get the number of rows from a result identifier. #### Tags:
return: | see above
throws: | Bs_Exception if not supported by this DB or any other error.
access: | public
Overridden in child classes as: Bs_MsSql::numRows() Get the number of rows from a result set. Bs_MySql::numRows() Get the number of rows from a result set. Bs_Oci::numRows() Get the number of rows from a result set. #### Parameters:
$result | $result | result identifier
[ Top ] ### method parseDsn [line 1219]
`void parseDsn( mixed $dsn)`
#### Tags:
todo: | all
[ Top ] ### method provides [line 281]
`bool provides( $feature $feature)`
Tell whether a DB implementation or its backend extension supports a given feature. currently, these features are reported (see constructor of subclassing class, like Bs_MySql) 'prepare', 'pconnect', 'transactions', 'innerSelects', 'insertId', 'affectedRows', 'numRows', 'numCols' #### Tags:
return: | whether this DB implementation supports $feature (or NULL if $feature not known).
access: | public
#### Parameters:
$feature | $feature | name of the feature
[ Top ] ### method quoteArgs [line 1115]
`string &quoteArgs( array $arr, [string $glue = ', '])`
Takes a hash and returns a string for an sql query. example 1: $arr = array('name' => 'tom', 'age' => '35', 'sex' => 'm'); $sqlQuery = "UPDATE tbl SET " . $db->quoteArgs($arr, ', ') . " WHERE ID = 1"; => "UPDATE tbl SET name = 'tom', age = '35', sex = 'm' WHERE ID = 1"; example 2: $arr = array('name' => 'tom', 'age' => '35', 'sex' => 'm'); $sqlQuery = "SELECT * FROM tbl WHERE " . $db->quoteArgs($arr, ' AND '); => "SELECT * FROM tbl WHERE name = 'tom' AND age = '35' AND sex = 'm'"; Note I: $this->escapeString() is used on the $value. Note II: boolean values are converted to ints. #### Tags:
return: | a string to include in an sql query.
#### Parameters:
array | $arr | an associative array.
string | $glue | a delimiter, default is ', ', could be ' AND ' or ' OR ' ...
[ Top ] ### method read [line 389]
`resorce read( string $query)`
Issue a select query and return a resource (or statement for oci). #### Tags:
return: | handler (or statement for oci)
see: | Bs_Db::rsRead(), Bs_Db::countRead()
throws: | Bs_Exception
access: | public
#### Parameters:
string | $query | A read only SQL statement.
[ Top ] ### method rollback [line 1274]
`TRUE rollback( )`
Rollback last query #### Tags:
return: | on success.
throws: | Bs_Exception if not supported by this DB or on any other error.
access: | public
Overridden in child classes as: Bs_MsSql::rollback() Rollback last query Bs_MySql::rollback() Rollback last query [ Top ] ### method rsRead [line 408]
`"result &rsRead( string $query)`
Issue a select query and return an instance of Bs_ResultSet. #### Tags:
return: | set"-object an instance of Bs_ResultSet
see: | Bs_ResultSet
see: | Bs_Db::read(), Bs_Db::countRead()
throws: | Bs_Exception
access: | public
#### Parameters:
string | $query | A read only SQL statement.
[ Top ] ### method setPointer [line 1287]
`mixed setPointer( $result $result, int $absolutPos)`
Set the internal row pointer of the result id to point to the specified row number. The next fetch call would return that row. #### Tags:
return: | TRUE on success, NULL on a row number (param $num) that is out of bounds.
throws: | Bs_Exception if not supported by this DB or on any other error.
access: | public
Overridden in child classes as: Bs_MsSql::setPointer() Sets the internal row pointer of the result id to point to the specified row number. Bs_MySql::setPointer() Sets the internal row pointer of the result id to point to the specified row number. #### Parameters:
int | $absolutPos | the row number, which starts at position 0.
$result | $result | result identifier
[ Top ] ### method startTransaction [line 1254]
`TRUE startTransaction( )`
Starts a transaction #### Tags:
return: | on success.
throws: | Bs_Exception if not supported by this DB or on any other error.
access: | public
Overridden in child classes as: Bs_MsSql::startTransaction() Starts a transaction As optional parameter you can pass a transaction ID. Bs_MySql::startTransaction() Starts a transaction As optional parameter you can pass a transaction ID. [ Top ] ### method toString [line 1028]
`string toString( )`
Returns a string with information about the current state of this db object. for security reason, no user/pass information is returned here because someone (you?) might log the returned value. #### Tags:
access: | public
Overrides Bs_Object::toString() (Dumps the content of this object to a string using PHP's var_dump().) [ Top ] ### method write [line 453]
`bool write( string $query)`
Issue a write query (insert, update, delete, replace, drop, alter, create). #### Tags:
return: | true on success, otherwise throws an exception.
see: | Bs_Db::countWrite(), Bs_Db::idWrite()
throws: | Bs_Exception
access: | public
#### Parameters:
string | $query | A modifing SQL statement.
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:08:44 +0100 by phpDocumentor 1.2.3