blueshoes php application framework and cms            core_db
[ class tree: core_db ] [ index: core_db ] [ all elements ]

Class: Bs_Odbc

Source Location: /core/db/Bs_Odbc.class.php

Class Overview

Bs_Object
   |
   --Bs_Db
      |
      --Bs_Odbc

*********************************************************************** dependencies: Bs_Db


Author(s):

Version:

  • 4.3.$Revision: 1.2 $ $Date: 2003/08/09 15:17:44 $

Copyright:

  • blueshoes.org

Variables

Methods


Inherited Variables

Inherited Methods

Class: Bs_Db

Bs_Db::Bs_Db()
constructor.
Bs_Db::affectedRows()
Gets the number of rows affected by the last data manipulation query.
Bs_Db::assertExtension()
Load a PHP database extension if it is not loaded already.
Bs_Db::autoCommit()
Turn autoCommit on or off
Bs_Db::commit()
Commit last query
Bs_Db::countRead()
Issue a select query and return the number of 'affected' rows.
Bs_Db::countWrite()
Issue a write query (update, delete, replace) and return the number of affected rows.
Bs_Db::dbPing()
Tells whether we're connected.
Bs_Db::escapeString()
Escape string for the query.
Bs_Db::fetchRow()
Fetch a row and return it as vector or hash depending on the fetchMode.
Bs_Db::formatDateForDb()
format and return date string in database date format.
Bs_Db::formatDatetimeForDb()
format and return datetime string in database datetime format.
Bs_Db::formatTimestampForDb()
format and return timestamp string in database timestamp format.
Bs_Db::freeResult()
Free the internal resources associated with $result.
Bs_Db::getAll()
Fetch the entire data given by the param $source into a hash.
Bs_Db::getAssoc()
Fetch the entire data given by the param $source into a hash using the first column as the key.
Bs_Db::getAssoc2()
hash array COLUMN BY COLUMN not record by record.
Bs_Db::getAssoc3()
group the values of one field by another one. see the example.
Bs_Db::getCol()
Fetch a full OR fraction col of data as vector given by the param $source.
Bs_Db::getDsn()
Return the _dsnInfo-hash.
Bs_Db::getErrorMessage()
Return a textual error message for a bs DB error code
Bs_Db::getFieldValue()
Returns 1-n db-field values.
Bs_Db::getNumRecords()
Returns the number of records that get selected for a given query.
Bs_Db::getOne()
Fetch a single value from a data amount given by the param $source.
Bs_Db::getRow()
Fetch a full row of data as vector or hash given by the param $source.
Bs_Db::idWrite()
Issue an insert query on a table with an auto_increment field and return the newly inserted id.
Bs_Db::insertId()
Get the id generated from the previous INSERT operation.
Bs_Db::isManipulation()
Tells whether a query is a data manipulation query (insert, update, delete replace, alter, drop, create).
Bs_Db::nativeErrorCode()
Returns the numerical native error code from the previous DB operation or 0 (zero) if no error occured.
Bs_Db::nativeErrorMsg()
Returns the native error text from the previous DB operation or '' (empty string) if no error occured.
Bs_Db::numCols()
Get the number of columns (fields) in a result identifier.
Bs_Db::numRows()
Get the number of rows from a result identifier.
Bs_Db::parseDsn()
Bs_Db::provides()
Tell whether a DB implementation or its backend extension supports a given feature.
Bs_Db::quoteArgs()
Takes a hash and returns a string for an sql query.
Bs_Db::read()
Issue a select query and return a resource (or statement for oci).
Bs_Db::rollback()
Rollback last query
Bs_Db::rsRead()
Issue a select query and return an instance of Bs_ResultSet.
Bs_Db::setPointer()
Set the internal row pointer of the result id to point to the specified row number.
Bs_Db::startTransaction()
Starts a transaction
Bs_Db::toString()
Returns a string with information about the current state of this db object.
Bs_Db::write()
Issue a write query (insert, update, delete, replace, drop, alter, create).

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 19]
*********************************************************************** dependencies: Bs_Db



Tags:

since:  bs4.3
status:  experimental
pattern:  singleton: (pseudostatic)
access:  public
copyright:  blueshoes.org
version:  4.3.$Revision: 1.2 $ $Date: 2003/08/09 15:17:44 $
author:  andrej arn <at blueshoes dot org>


[ Top ]


Class Variables

$format = array(
    'date'       => "'Y-m-d'",           'datetime'   => "'Y-m-d H:i:s'",     'timestamp'  => "'YmdHis'",        )

[line 49]

some database specific formats. overwrites parent.



Tags:

todo:  update this for odbc
see:  Bs_Db::formatDateForDb(), Bs_Db::formatDatetimeForDb(), Bs_Db::formatTimestampForDb()
access:  public

Type:   array
Overrides:   Array


[ Top ]



Class Methods


constructor Bs_Odbc [line 59]

Bs_Odbc Bs_Odbc( )

Constructor.



[ Top ]

method connect [line 80]

int connect( $dsn $dsn, [$persistent $persistent = TRUE])

Connect to a database server and log in as the specified user.

use (select) the given db, if any.

NOTE I: If we are already connected to somewhere (no matter where), the existing db connection gets closed first.

NOTE II: It's possible to get back an exception but the connection was successfull. Probably the given default database could not be selected => BS_DB_ERROR_CANNOT_SELECT_DB




Tags:

return:  resource id # on success
throws:  Bs_Exception: one of BS_DB_ERROR_INVALID_DSN, BS_DB_ERROR_CONNECT_FAILED, BS_DB_ERROR_CANNOT_SELECT_DB
access:  public


Parameters:

$dsn   $dsn   the data source name as an array. The parseDSN() is deactivated, would need cleanup.
$persistent   $persistent   (opt) whether the connection should be persistent. (Default TRUE)

[ Top ]

method disconnect [line 135]

bool disconnect( )

Log out and disconnect from the database.



Tags:

return:  TRUE if we already have been or are now disconnected, FALSE if we're on a persistant conn.
see:  Bs_Db::_disconnect()
throws:  NULL if we cannot tell in which state the connection is now. internally for this object, the connection is 'closed'.
access:  public


[ Top ]

method escapeString [line 328]

string escapeString( string $query)

Escape string for mysql query.

This method is a wrapper for mysql_escape_string() and overwrites its parent method. mysql_escape_string() is new sinde php403 or 404 and by now it's not documented.

I have found this in the mysql manual: mysql_real_escape_string() Escapes special characters in a string for use in a SQL statement taking into account the current charset of the connection. mysql_escape_string() Escapes special characters in a string for use in a SQL statement. So watch out for mysql_real_escape_string() to be implemented in php...

You can find a pure php impelementation here: http://www.zend.com/codex.php?id=204&single=1




Tags:

return:  the escaped query


Overrides Bs_Db::escapeString() (Escape string for the query.)

Parameters:

string   $query  

[ Top ]

method fetchRow [line 181]

mixed &fetchRow( $result $result, [int $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.

A clean example usage of this method to fetch rows into an array:

while ($row = $this->fetchRow($res, $fetchMode)) { if (isEx($row)) { $row->stackTrace('was here: currentFunction()', __FILE__, __LINE__); return $row; } $ret[] = $row; }




Tags:

return:  vector, hash or NULL if there is no more data
throws:  Bs_Exception on error.
access:  public


Overrides Bs_Db::fetchRow() (Fetch a row and return it as vector or hash depending on the fetchMode.)

Parameters:

int   $fetchMode   (opt) (default BS_DB_FETCHMODE_ASSOC) see above.
$result   $result   db result identifier

[ Top ]

method fieldLen [line 265]

int fieldLen( resource $result, int $offset)

Returns the length of a field at the specified offset from a result id.

NOTE: Not the actual value length but the max possible field space: E.g. if a varchar(20) has the value 'foobar' it returns 20 not 6. This is a wrapper for odbc_field_len().




Tags:

return:  the field length.
throws:  Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception on a field index that doesn't exist or any other error.
access:  public


Parameters:

resource   $result   a result identifier.
int   $offset   fieled offset in result beginning with 0.

[ Top ]

method fieldName [line 246]

string fieldName( resource $result, int $offset)

Get the field name at the specified offset from a result id.

This is a wrapper for odbc_field_name().




Tags:

return:  the field name
see:  tableName(), databaseName(), listFields(), fetchFieldNames()
throws:  Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception on a field index that doesn't exist or any other error.
access:  public


Parameters:

resource   $result   a result identifier you got from a query.
int   $offset   fieled offset in result beginning with 0.

[ Top ]

method fieldType [line 295]

string fieldType( resource $result, [int $offset = 1])

Get the type of a field at the specified offset from a result id.

This is a wrapper for odbc_field_type().




Tags:

throws:  Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception on a field index that doesn't exist or any other error.
access:  public


Parameters:

resource   $result   a result identifier.
int   $offset   (field offset in result, DOCUMENTED AS BEGINNINT WITH 1, NOT 0! is that correct?)

[ Top ]

method freeResult [line 231]

void freeResult( $result $result)

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.

All associated result memory is automatically freed at the end of the script's execution.




Tags:

return:  (any errors are ignored)
access:  public


Overrides Bs_Db::freeResult() (Free the internal resources associated with $result.)

Parameters:

$result   $result   db result identifier or DB statement identifier

[ Top ]

method listTables [line 307]

void listTables( [mixed $dbName = NULL])

see odbc_tables()



Tags:

todo:  all


[ Top ]

method nativeError [line 368]

string nativeError( )

Returns the native error from the previous db operation or '' (empty string) if no error occured.



Tags:

return:  native db error code and message like "code:text" or empty string if no error.
see:  Bs_Odbc::nativeErrorCode(), Bs_Odbc::nativeErrorMsg()
access:  public


[ Top ]

method nativeErrorCode [line 340]

int nativeErrorCode( )

Returns the numerical native error code from the previous db operation or 0 (zero) if no error occured.

This method is a wrapper for odbc_error().




Tags:

return:  native MySQL error code
see:  Bs_Odbc::nativeErrorMsg(), Bs_Odbc::nativeError()
access:  public


Overrides Bs_Db::nativeErrorCode() (Returns the numerical native error code from the previous DB operation or 0 (zero) if no error occured.)

[ Top ]

method nativeErrorMsg [line 355]

string nativeErrorMsg( )

Returns the native error text from the previous db operation or '' (empty string) if no error occured.

This method is a wrapper for odbc_errormsg(). HINT: Better use nativeErrorCode() before calling this method, or call nativeError() directly.




Tags:

return:  native db error message
see:  Bs_Odbc::nativeErrorCode(), Bs_Odbc::nativeError()
access:  public


Overrides Bs_Db::nativeErrorMsg() (Returns the native error text from the previous DB operation or '' (empty string) if no error occured.)

[ Top ]

method numCols [line 212]

int numCols( $result $result)

Get the number of columns (fields) from a result set.



Tags:

return:  the number of columns per row in $result
throws:  Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception if odbc_num_fields() failed somehow
access:  public


Overrides Bs_Db::numCols() (Get the number of columns (fields) in a result identifier.)

Parameters:

$result   $result   db result identifier

[ Top ]

method _dbErrorToBsError [line 425]

mixed _dbErrorToBsError( int $dbError)

Maps error codes of the current dbms to bs-dbErrorCodes.



Tags:

return:  (int bs-dbErrorCode if the error code is mapped, bool FALSE otherwise.


Parameters:

int   $dbError  

[ Top ]


Documentation generated on Mon, 29 Dec 2003 21:12:18 +0100 by phpDocumentor 1.2.3