BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/db/Bs_MsSql.class.php
BlueShoes Application Framework - db

Bs_MsSql

Bs_Object
   |
  +-- Bs_Db
     |
    +-- Bs_MsSql

This is the API for MSSQL it's an extention of the abstract class Bs_Db.class.php

 

public class Bs_MsSql extends Bs_Db

This is the API for MSSQL it's an extention of the abstract class Bs_Db.class.php
A good understanding of the built in MSSQL functions in php is needed to create clean, goodcode using these classes. please RTFphpM first. here i'll try to avoid copying the php docover and over again.known problems/bugs:1)2002-02-27 --andrejSYSTEM CONFIG:php running on the local workstation, connecting to the in-house sql-server.workstation:os : winnt 2000 pro (workstation) build 2195php : version 4.1.1php_mssql.dll : 44kb (45056 bytes)mssql: sql server enterprise manager (version unknown)server:os : winnt 2000 servermssql : mssql 2000 i think.PROBLEM:i was connecting using php code to the sql server. everything worked fine.then after issueing the query"SELECT name FROM master.dbo.sysdatabases ORDER BY name"it would not connect anymore. actually i think it was already short beforedoing this one, i cannot tell anymore. so i dunno if it matters.i went into the the sql server enterprise manager, and was able tore-connect using exactly the same dsn-info. so the sql server was fine.what helped was restarting apache. crap.###########################################################################see http://www.php.net/manual/en/function.mssql-connect.php for all thisand much more...---------------------------------------------------------------------------Remember, you must build Linux/Unix PHP with Sybase support in order to getMSSQL support../configure --with-sybase=/opt/sybase-11.9.2/For Linux, you can get the required "Adaptive Server Enterprise"Sybase RPMs from http://www.sybase.com/products/databaseservers/linux/You should then put any MSSQL database you want to connect to in the/opt/sybase-11.9.2/interfaces file, in the formatEXAMPLE_Hostquery tcp ether IP_OR_FQDN PORTNUMBERWhere PORTNUMBER is usually (but not always) 1433In your code, refer to the EXAMPLE_Host in your connect string likethis;mssql_connect("EXAMPLE_Hostname","username","Password")or die("Connection error");---------------------------------------------------------------------------22-Mar-2000 12:05The sybase libraries work great for connecting to MS SQL Server 6.5databases. SQL Server 7.0, however, is another matter. a good discussionon this can be found under sybperl's site. I think they will work on 7.0sp 1 and the latest and greatest sybase libaries...---------------------------------------------------------------------------manglewolf@yahoo.com22-Mar-2000 12:08In addition to 6.5/7.0 issues, remember that the sybase libs need anenvironment variable<pre>SYBASE=/path/to/intf-file</pre> to be available. I'veusually added it to the globally available environment variables.---------------------------------------------------------------------------scott@uq.edu.au23-Apr-2000 08:02O.K.- Windows 2000 Server, MSSQL7, PHP 3.0.16...You need to have the following:ntwdblib.dll (mine was 348K) in \winnt\system32 - search for it atftp.lycos.com if you don't have it.extension=php3_mssql70.dll uncommented in php.iniAnd mssql_connect() etc. should work.Scott.scott@uq.edu.au29-Apr-2000 12:07I've also tested this setup under PHP4 with Zend and it appears to be o.k.###########################################################################Quick overview of the features of MSSQL----------------------+------------------------------------------------------------------------available | comments----------------------+------------------------------------------------------------------------transactions | nonefulltext indexing | nonesubselects | nonestored procedures | nonetriggers | noneforeign keys | noneviews | none----------------------+------------------------------------------------------------------------not available | comments----------------------+------------------------------------------------------------------------'foreign chars' | No support for spaces, foreign and special chars, and reserved words| in field, table and database names. MS-Access and Oracle support this.The following php MSSQL functions are *NOT* implemented here because we don't want youto use them:mssql_fetch_object() => Use fetchRow() which makes use of mysql_fetch_assoc() or mysql_fetch_row()mssql_fetch_array() => Use fetchRow() which makes use of mysql_fetch_assoc() or mysql_fetch_row()mssql_result() => as you can reas in the manual, this function is not really recommended.also see the MySql implementation. Also see Bs_Db->getOne()TODO----This class is accurate for MsSQL __version__.- please check the following methods to be up to date:2do > fieldFlags(), hasFieldFlag(), fieldType(), getTableProperties(), getTableInfo(), getTableType(),2do > getIniVar(), getStatusVar()Make sure the existing code doesn't break because of your changes! thanx.- recode some functions more down the file for mssql (taken from mysql).- code the transaction stuff- implement the stored procedures functionality.- i wonder if we should move more logic into bs_db.class (that is the same in the mssql and mysql implementation).i don't want to copy the same code blocks over and over again for every db vendor. but then how many impl. willwe write?dependencies: Bs_Db

Authors
Version4.0.$id$
Copyrightblueshoes.org

 

Methods inherited from Bs_Db

&getdbobject, bs_db, &getdsn, provides, getnumrecords, getfieldvalue, read, &rsread, countread, write, _vendorspecificwritemod, countwrite, idwrite, &getone, &getrow, &getcol, &getassoc, &getassoc2, &getall, assertextension, tostring, formatdatefordb, formatdatetimefordb, formattimestampfordb, "eargs, ismanipulation, &_raiseerror, geterrormessage, parsedsn, fetchrow, _disconnect, fetchdbnames

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

void

Bs_MsSql()

Constructor.
void

autoCommit([ string $on ])

Turn autoCommit on or offWarning: documentation is missing.
void

startTransaction([ string $transactionId ])

Starts a transactionWarning: documentation is missing.
void

commit([ string $transactionId ])

Commit the current or given transaction.Warning: documentation is missing.
void

rollback([ string $transactionId ])

Rollback last queryWarning: documentation is missing.
int

connect(array $dsn, string $persistent)

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

disconnect()

Log out and disconnect from the database.
bool

selectDb(string $db)

Select a MsSQL database.
mixed

&fetchRow(int $result, string $fetchMode)

Fetch a row and return it as vector or hash depending on the fetchMode.
int

numCols( $result)

Get the number of columns (fields) from a result set.Warning: documentation is missing.
int

numRows( $result)

Get the number of rows from a result set.Warning: documentation is missing.
int

affectedRows()

Gets the number of rows affected by the data manipulation query.Warning: documentation is missing.
int

insertId()

Returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query on this thread.Warning: documentation is missing.
void

freeResult( $result)

Free the internal resources associated with $result. Only needs to be called if you areWarning: documentation is missing.
string

fieldName(int $result, $offset)

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

tableName(int $result, $offset)

Returns the name of the table that the field (specifed by an offset) is in.
string

tableName2(int $result, $offset)

Get the name of the specified table in a result you got from mysql_list_tables().
string

databaseName(int $result, $offset)

Get the name of the specified db in a result you got from mysql_list_dbs().
int

fieldLen(int $result, $offset)

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

fieldFlags(int $result, string $offset, string $format)

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

hasFieldFlag(int $result, string $offset, $flag)

Tells whether the field has the given flag. The field is specified by offset in a result id.
string

fieldType(int $result, integer $offset)

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

listDatabases()

returns a result identifier for the available databases.
void

listTables([ string $dbName ])

returns a result identifier for the available tables in the given database.
void

listFields(string $tableName, [ string $dbName ])

Retrieves information about the given tablename.Warning: documentation is missing.
mixed

&fetchDatabaseNames([ string $format, string $useCache ])

Returns the available db names.
mixed

&fetchTableNames([ string $dbName, string $format, string $useCache ])

Return the table names of the given database.
mixed

&fetchFieldNames(string $tblName, [ string $dbName, string $format, string $useCache ])

Return the field names of the given database table.
void

&getDbStructure([ string $dbName, string $useCache ])

Return a 2-D array of tables and fieldnames found in the given db.
object [unknown]

fetchField(int $result, string $offset)

Returns an object containing field information (of the table structure).
bool

fieldExists(mixed $fieldName, string $tableName, [ string $dbName, string $useCache ])

Tells whether the db field (or fields) exist or not.
bool

tableExists(mixed $tableName, [ string $dbName, string $useCache ])

Tells whether the db table (or tables) exist or not.
bool

databaseExists(mixed $dbName, [ string $useCache ])

Tells whether the database (or databases) exist or not.
array

getTableInfo(string $tblName, [ string $dbName ])

Returns an hash holding information about the given db table.
string

getTableType(string $tblName, [ string $dbName ])

Returns the table type of the specified db table.
bool

tableHasTransactions(string $tblName, [ string $dbName ])

bool

serverSupportsTableType(string $tableType)

Tells whether the given table type is supported by the server or not.
mixed

getIniVar([ string $key, string $useCache ])

Return the value of the currently used ini setting var.
mixed

getStatusVar([ string $key, string $useCache ])

Return the value of the specified status var.
string

getClientInfo()

Returns a string that represents the client library version.
string

getHostInfo()

Returns a string describing the type of connection in use, including the server host name.
int

getProtocolInfo()

Returns the protocol version used by current connection.
string

getServerInfo()

Returns a string that represents the server version number.
string

escapeString(string $query)

Escape string for mssql query.Warning: documentation is missing.
mixed

setPointer(int $result, $absolutPos)

Sets the internal row pointer of the result id to point to the specified row number.Warning: documentation is missing.
void

isValidName(string $string)

Tells if a name for a db, table or field is accepted by mysql or not.
int

isReservedWord(string $word)

Tells if a word is a reserved word for mysql.
string

nativeErrorMsg()

Returns the native error text from the previous MsSQL operation or '' (empty string) ifWarning: documentation is missing.
string

nativeError()

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

_dbErrorToBsError(int $dbError)

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

Private Method Summary

int

_query(string $query)

Send a query to MsSQL and return the result, no matter what it was.Warning: documentation is missing.
mixed

getOpenTables([ string $dbName, string $return ])

Returns the currently open tables in $db.
int

nativeErrorCode()

returns the native error code from the mssql database.Warning: documentation is missing.
object an

_mssqlRaiseError([ string $errNo, string $file, string $line, string $weight, string $msg ])

Throw an error. This method makes use of Bs_Db->_raiseError().
void

getTableProperties( $tblName, string $dbName)

Warning: documentation is missing.
void

tableInfo( $result, string $mode)

Warning: documentation is missing.
void

switchUser( $user, $pass)

Warning: documentation is missing.

Fields inherited from Bs_Db

$_connection, $_connected, $_persistent, $_dsninfo, $_lastquery, $bs_date, $_bs_system, $_features, $format

Private Field Summary

string

$_databaseNames

cached result from fetchDatabaseNames().
string

$_tableNames

cached result from fetchTableNames().
string

$_fieldNames

cached result from fetchFieldNames().
string

$_iniVars

cached result from getIniVar().
string

$_statusVars

cached result from getStatusVar().
string

$_currentlyOpenTransactionID

Holds the 'transaction ID'. (If an trans. ID was set).

Private Constant Summary

BS_MSSQL_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

Bs_MsSql

public void Bs_MsSql( )

  Constructor.

Returns void


autoCommit

public void autoCommit( [ string $on ] )

  Turn autoCommit on or off

Warning: documentation is missing.

Parameter
string $on = >>FALSE<<
(opt) If TRUE turn on else off (default TRUE)
Returns void

Throws Bs_Exception if not supported by this DB

startTransaction

public void startTransaction( [ string $transactionId ] )

  Starts a transaction
As optional parameter you can pass a transaction ID.When working with transactions, I run often in the situation, that I have a 'Master' routine callingother sub-routines and some sub-routines start their own transation. Multiple transaction 'starts'don't bother the Db, the transaction just stays open *BUT* the first to call commit or rollback willterminate the transaction! To prevent sub-routines from closing the 'Masters' transaction you maystart a transaction and pass a 'transaction ID'. Folloing commits/rollbacks are ignored as long as itdosen't match the 'transaction ID' given at start.NOTE I: Be aware of the highter deadlocking risk, when using 'transaction ID'.NOTE II: Make sure that you end the open transaction when using 'transaction ID'.Otherwise the transaction will *stay open*.

Warning: documentation is missing.

Parameter
string $transactionId = >>''<<
(opt). See text above.
Returns void

Throws Bs_Exception if not supported by this DB or on any other error.

commit

public void commit( [ string $transactionId ] )

  Commit the current or given transaction.

Warning: documentation is missing.

Parameter
string $transactionId = >>''<<
(opt). See $this->startTransaction.
Returns void

Throws Bs_Exception if not supported by this DB or on any other error.

rollback

public void rollback( [ string $transactionId ] )

  Rollback last query

Warning: documentation is missing.

Parameter
string $transactionId = >>''<<
(opt). See $this->startTransaction.
Returns void

Throws Bs_Exception if not supported by this DB or on any other error.

connect

public int connect( array $dsn, string $persistent )

  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

Parameter
array $dsn
. The parseDSN() is deactivated, would need cleanup.
string $persistent
Warning: documentation is missing.
Returns int

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

disconnect

public bool disconnect( )

  Log out and disconnect from the database.
Note: mssql_close() will not close persistent links (created by mssql_pconnect()).

Returns bool

TRUE if we already have been or are now disconnected, FALSE if we're on a persistant conn.

Throws NULL if we cannot tell in which state the connection is now. internally for this object, the connection is 'closed'.

selectDb

public bool selectDb( string $db )

  Select a MsSQL database.
this is a wrapper for mssql_select_db().

Parameter
string $db
a database name.
Returns bool

true on success, false on failure.


&fetchRow

public mixed &fetchRow( int $result, string $fetchMode )

  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 correspondsto 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 ($this->isException($row)) {$row->stackTrace('was here: currentFunction()', __FILE__, __LINE__);return $row;}$ret[] = $row;}

Parameter
int $result
(opt) (default BS_DB_FETCHMODE_ASSOC) see above.
string $fetchMode
Warning: documentation is missing.
Returns mixed

vector , hash or NULL if there is no more data

Throws Bs_Exception on error.

numCols

public int numCols( $result )

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

Warning: documentation is missing.

Parameter
$result
Warning: documentation is missing.
Returns int

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 mssql_num_fields() failed somehow

numRows

public int numRows( $result )

  Get the number of rows from a result set.

Warning: documentation is missing.

Parameter
$result
Warning: documentation is missing.
Returns int

the number of rows in $result

Throws Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception if mssql_num_rows() failed somehow.

affectedRows

public int affectedRows( )

  Gets the number of rows affected by the data manipulation query.
For other queries, this function returns FALSE.RTFM for mysql_affected_rows() !!!If the last query was a DELETE query with no WHERE clause, all of the recordswill have been deleted from the table but this function will return zero.hint I: use "DELETE FROM tbl WHERE 1=1"hint II: maybe you are looking for "TRUNCATE TABLE table_name" anyway.

Warning: documentation is missing.

Returns int

number of rows affected by the last query or FALSE none affected

Throws Bs_Exception if mssql_affected_rows() fails.

insertId

public int insertId( )

  Returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query on this thread.
Returns 0 if the previous query does not generate an AUTO_INCREMENT value.If you need to save the value for later, be sure to call this function immediately after the querythat generates the value.This method is save, thanks to rick@surveyor.com for the information :)

Warning: documentation is missing.

Returns int

A value>=1 (the ID) or 0 (no AUTO_INCREMENT value given) or FLASE (see above)

Throws Bs_Exception if not supported by this DB or any other error.

freeResult

public void freeResult( $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.

Warning: documentation is missing.

Parameter
$result
Warning: documentation is missing.
Returns void


fieldName

public string fieldName( int $result, $offset )

  Get the field name at the specified offset from a result id.
This is a wrapper for mssql_field_name().

Parameter
int $result
fieled offset in result beginning with 0.
$offset
Warning: documentation is missing.
Returns string

the field name

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.
See Also tableName(), databaseName(), listFields()

tableName

public string tableName( int $result, $offset )

  Returns the name of the table that the field (specifed by an offset) is in.
This is a wrapper for mysql_field_table().

Parameter
int $result
fieled offset in result beginning with 0.
$offset
Warning: documentation is missing.
Returns string

the table name

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.
See Also fieldName(), databaseName(), listTables()

tableName2

public string tableName2( int $result, $offset )

  Get the name of the specified table in a result you got from mysql_list_tables().
This is a wrapper for mysql_tablename().

Parameter
int $result
fieled offset in result beginning with 0.
$offset
Warning: documentation is missing.
Returns string

the table name
@throw 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.

See Also fieldName(), tableName(), databaseName(), listTables()

databaseName

public string databaseName( int $result, $offset )

  Get the name of the specified db in a result you got from mysql_list_dbs().
This is a wrapper for mysql_db_name().I don't think you ever need this method ...

Parameter
int $result
fieled offset in result beginning with 0.
$offset
Warning: documentation is missing.
Returns string

the db name

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.
See Also fieldName(), tableName(), listDatabases()

fieldLen

public int fieldLen( int $result, $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 mysql_field_len() AND mysql_fieldlen() .

Parameter
int $result
fieled offset in result beginning with 0.
$offset
Warning: documentation is missing.
Returns int

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.

fieldFlags

public mixed fieldFlags( int $result, string $offset, string $format )

  Get the flags of a field at the specified offset from a result id.
This is a wrapper for mysql_field_flags().The returned value is dependent on the $format param. E.g.:'string' => 'not_null primary_key blob''vector' => array('not_null', 'primary_key', 'blob')'hash' => array('not_null' => TRUE, 'primary_key' => TRUE, 'unique_key' => FALSE, ...)Please check the docs for mysql_field_flags to get a list of the current flags supported.By now, they are: (***IF THEY HAVE CHANGED, PLEASE UPDATE THE CODE OF THIS METHOD!***)"not_null", "primary_key", "unique_key", "multiple_key", "blob", "unsigned", "zerofill","binary", "enum", "auto_increment", "timestamp".I have read somewhere that the 'flags' blob, enum and timestamp are deprecated because theyare not flags but field types. You're descouraged to use them.

Parameter
int $result
fieled offset in result beginning with 0.
string $offset
the return type, can be 'string', 'array' or 'assoc'.
string $format
Warning: documentation is missing.
Returns mixed

(based on the param $format) see description.

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.

hasFieldFlag

public boolean hasFieldFlag( int $result, string $offset, $flag )

  Tells whether the field has the given flag. The field is specified by offset in a result id.
This method uses $this->fieldFlags() to get the data. Check it's documentation!

Parameter
int $result
fieled offset in result beginning with 0.
string $offset
the flag name.
$flag
Warning: documentation is missing.
Returns boolean

Throws Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, NULL if the flag is not known. maybe not supported in this mysql version...

fieldType

public string fieldType( int $result, integer $offset )

  Get the type of a field at the specified offset from a result id.
This is a wrapper for mssql_field_type().--------------------------------------------------------------------------CAUTION: mysql used to return wrong names. maybe mssql does the same?please verify. (from mysql:)+----------------------------+| mysql type | returned as |+ ------------+--------------+| tinyint | int | // php4.0.4pl1 used to return unknown. Corrected in php4.0.5| smallint | int || mediumint | int || int | int || bigint | int || float | real || double | real || decimal | real || date | date || datetime | datetime || timestamp | timestamp || year | year | // php4.0.4pl1 used to return unknown. Corrected in php4.0.5| char | string || varchar | string || tinyblob | blob || blob | blob || mediumblob | blob || longblob | blob || enum | string || set | string |+----------------------------+--------------------------------------------------------------------------

Parameter
int $result
fieled offset in result beginning with 0. default is 0.
integer $offset
Warning: documentation is missing.
Returns string

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.

listDatabases

public void listDatabases( )

  returns a result identifier for the available databases.
note I: with mssql you see all db's even if you have no access to them. that may be different in other rdbms.

Returns void

Throws Bs_Exception.
See Also listFields(), listTables()

listTables

public void listTables( [ string $dbName ] )

  returns a result identifier for the available tables in the given database.
note I: tables may exist but if you don't have the perms, you won't see them!note II: only 'U'ser tables will be listed. no 'S'ystem stuff.

Parameter
string $dbName = >>NULL<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
Returns void

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception if something fails.
See Also listFields(), listDatabases()

listFields

public void listFields( string $tableName, [ string $dbName ] )

  Retrieves information about the given tablename.
This is a wrapper for mysql_list_fields().NOTE: Fields may exist but if you don't have the perms, you won't see them!

Warning: documentation is missing.

Parameter
string $tableName
the db table name.
string $dbName = >>NULL<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
Returns void

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception if mysql_list_fields() failed somehow.
See Also listTables(), listDatabases()

&fetchDatabaseNames

public mixed &fetchDatabaseNames( [ string $format, string $useCache ] )

  Returns the available db names.
If successfull the data will be cached for further calls.NOTE: You'll see all db's even if you don't have the rights to access them.The returned value is dependent on the $format param. E.g.:'vector' => array(db1, db2, db3)'string' => 'db1, db2, db3'

Parameter
string $format = >>'vector'<<
the return type. can be one of 'vector' (default) or 'string'. see description.
string $useCache = >>TRUE<<
default is TRUE. if set to true and the method has been executed successfully before, the previous result will be used/returned.
Returns mixed

(see param $format)

See Also listDatabases()

&fetchTableNames

public mixed &fetchTableNames( [ string $dbName, string $format, string $useCache ] )

  Return the table names of the given database.
If successfull the data will be cached for further calls.NOTE: Tables may exist but if you don't have the perms, you won't see them!The returned value is dependent on the $format param. E.g.:'vector' => array(table1, table2, table3)'string' => 'table1, table2, table3'

Parameter
string $dbName = >>NULL,<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
string $format = >>'vector'<<
the return type. can be one of 'vector' (default) or 'string'. see description.
string $useCache = >>TRUE<<
default is TRUE. if set to true and the method has been executed successfully before for this db, the previous result will be used/returned.
Returns mixed

(see param $format)

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also getOpenTables()

&fetchFieldNames

public mixed &fetchFieldNames( string $tblName, [ string $dbName, string $format, string $useCache ] )

  Return the field names of the given database table.
If successfull the data will be cached for succeeding calls.NOTE: Fields may exist but if you don't have the perms, you may not see them!(that's how mysql is built, not sure about mssql.)The returned value is dependent on the $format param. E.g.:'vector' => array(field1, field2, field3)'string' => 'field1, field2, field3' we are using comma instead of space here becausesome db's allow you to use spaces inside of field names.

Parameter
string $tblName
a db table name
string $dbName = >>NULL,<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
string $format = >>'vector'<<
the return type. Can be one of 'vector' (default) or 'string'. see description.
string $useCache = >>TRUE<<
If TRUE (default) and the method has been executed successfully before for this db table, the previous result will be used/returned.
Returns mixed

(see param $format)

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.

&getDbStructure

public void &getDbStructure( [ string $dbName, string $useCache ] )

  Return a 2-D array of tables and fieldnames found in the given db.
If successfull the data will be cached for succeeding calls.NOTE: Tables and fields may exist but if you don't have the perms, you won't see them!The returned value sample:array( 'table_1' => array('field_1', 'field_2', 'field_3'),'table_2' => array('field_A', 'field_B', 'field_C', 'field_D'));

Parameter
string $dbName = >>NULL,<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
string $useCache = >>TRUE<<
If TRUE (default) and the method has been executed successfully before for this db table, the previous result will be returned.
Returns void

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.

fetchField

public object [unknown] fetchField( int $result, string $offset )

  Returns an object containing field information (of the table structure).
This has nothing to do with fetching data from a field, like fetchRow().You might be looking for something like php's mssql_result(), which is notsupported here for reasons mentioned in the header.See comments of unimplemented functions in the head of this file.This is a wrapper for mssql_fetch_field().

Parameter
int $result
if not given, the next field (that wasn't yet retrieved) will be used.
string $offset
Warning: documentation is missing.
Returns object [unknown]

Throws Bs_Exception with BS_DB_ERROR_INVALID_RS on an invalid $result param, Bs_Exception if mssql_fetch_field() failed somehow.

fieldExists

public bool fieldExists( mixed $fieldName, string $tableName, [ string $dbName, string $useCache ] )

  Tells whether the db field (or fields) exist or not.
NOTE I: Fields are not case sensitive in mysql (dbs and tables are, except on windows).This check is made case sensitive! So if your field is called 'myField',you'll get FALSE for 'myfield'.NOTE II: This method makes use of fetchFieldNames(). So if param $useCache is set to TRUE andfetchFieldNames() has been called before, the cached values will be used.

Parameter
mixed $fieldName
a db field name as a string, or an array with db field names.
string $tableName
a db table name
string $dbName = >>NULL,<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
string $useCache = >>TRUE<<
default is TRUE. see note II.
Returns bool

true if all fields exist, false if at least one doesn't.

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also tableExists(), databaseExists()

tableExists

public bool tableExists( mixed $tableName, [ string $dbName, string $useCache ] )

  Tells whether the db table (or tables) exist or not.
NOTE I: Databases and tables are file-based in mysql. So they are case sensitive, except on winblows.So for windows we have to do a case insensitive check.NOTE II: This method makes use of fetchTableNames(). So if param $useCache is set to TRUE andfetchTableNames() has been called before, the cached values will be used.

Parameter
mixed $tableName
a db table name as a string, or an array with db table names.
string $dbName = >>NULL,<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
string $useCache = >>TRUE<<
default is TRUE. see note II.
Returns bool

true if all tables exist, false if at least one doesn't.

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also fieldExists(), databaseExists()

databaseExists

public bool databaseExists( mixed $dbName, [ string $useCache ] )

  Tells whether the database (or databases) exist or not.
NOTE I: Databases and tables are file-based in mysql. So they are case sensitive, except on winblows.So for windows we have to do a case insensitive check.NOTE II: This method makes use of fetchDatabaseNames(). So if param $useCache is set to TRUE andfetchDatabaseNames() has been called before, the cached values will be used.

Parameter
mixed $dbName
a db name as a string, or an array with db names.
string $useCache = >>TRUE<<
default is TRUE. see note II.
Returns bool

true if all dbs exists, false if at least one doesn't.

Throws Bs_Exception
See Also fieldExists(), tableExists()

getTableInfo

public array getTableInfo( string $tblName, [ string $dbName ] )

  Returns an hash holding information about the given db table.
The returned hash (for mySQL 3.23.36) returns these 15 keys (values are examples):mysql> show table status like 'test';+------+--------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+----------------+---------+| Name | Type | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Create_options | Comment |+------+--------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+----------------+---------+| test | MyISAM | Dynamic | 4 | 22 | 88 | 4294967295 | 2048 | 0 | 5 | 2001-04-02 09:06:58 | 2001-04-02 09:07:00 | NULL | | |+------+--------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+----------------+---------+

Parameter
string $tblName
a db table name
string $dbName = >>NULL<<
. If empty (e.g: '' or NULL or 0) then use the current dbName.
Returns array

assoc . array see description.

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also tableHasTransactions(), getTableType()

getTableType

public string getTableType( string $tblName, [ string $dbName ] )

  Returns the table type of the specified db table.

Parameter
string $tblName
a db table name
string $dbName = >>NULL<<
a db name, default is NULL which means use the current one.
Returns string

the table type, currently one of 'MyISAM', 'ISAM', 'MERGE', 'HEAP', 'BDB', 'INNOBASE', 'GEMINI'

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also tableHasTransactions(), getTableInfo(), serverSupportsTableType()

tableHasTransactions

public bool tableHasTransactions( string $tblName, [ string $dbName ] )

 

Parameter
string $tblName
a db table name
string $dbName = >>NULL<<
a db name, default is NULL which means use the current one.
Returns bool

true if table supports transactions, false otherwise.

Throws Bs_Exception with BS_DB_ERROR_NEED_MORE_DATA if no $dbName available, Bs_Exception otherwise.
See Also getTableType(), getTableInfo()

serverSupportsTableType

public bool serverSupportsTableType( string $tableType )

  Tells whether the given table type is supported by the server or not.
NOTE: 'MyISAM', 'MERGE' and 'HEAP' are always supported. But if you still check for them, of courseTRUE is returned.The default mysql table type currently is MyISAM according to the manual. If you try to create onethat's not supported or not compiled into the server, a MyISAM table will be created instead. ISAMis deprecated, it is replaced by MyISAM. BDB, INNOBASE and GEMINI are transaction-safe, the othersare not.hrm. i've found an ini var called 'table_type' with the value 'MYISAM'. Prolly you can change thedefault table type there.

Parameter
string $tableType
one of 'MyISAM', 'ISAM', 'MERGE', 'HEAP', 'BDB', 'INNOBASE', 'GEMINI' (case doesn't matter).
Returns bool

true if the table type is supported, false otherwise.

Throws NULL if the given table type is not recognized, Bs_Exception otherwise.
See Also getTableType(), tableHasTransactions(), getTableInfo()

getIniVar

public mixed getIniVar( [ string $key, string $useCache ] )

  Return the value of the currently used ini setting var.
as of mySQL 3.23.36, the following 76 vars are available (with example values):+-------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Variable_name | Value |+-------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| ansi_mode | OFF || back_log | 50 || basedir | c:\mysql\ || binlog_cache_size | 32768 || character_set | latin1 || character_sets | latin1 big5 czech euc_kr gb2312 gbk sjis tis620 ujis dec8 dos german1 hp8 koi8_ru latin2 swe7 usa7 cp1251 danish hebrew win1251 estonia hungarian koi8_ukr win1251ukr greek win1250 croat cp1257 latin5 || concurrent_insert | ON || connect_timeout | 5 || datadir | c:\mysql\data\ || delay_key_write | ON || delayed_insert_limit | 100 || delayed_insert_timeout | 300 || delayed_queue_size | 1000 || flush | OFF || flush_time | 1800 || have_bdb | NO || have_gemini | NO || have_innobase | NO || have_isam | YES || have_raid | NO || have_ssl | NO || init_file | || interactive_timeout | 28800 || join_buffer_size | 131072 || key_buffer_size | 8388600 || language | c:\mysql\share\english\ || large_files_support | ON || log | OFF || log_update | OFF || log_bin | OFF || log_slave_updates | OFF || long_query_time | 10 || low_priority_updates | OFF || lower_case_table_names | 1 || max_allowed_packet | 1048576 || max_binlog_cache_size | 4294967295 || max_binlog_size | 1073741824 || max_connections | 100 || max_connect_errors | 10 || max_delayed_threads | 20 || max_heap_table_size | 16777216 || max_join_size | 4294967295 || max_sort_length | 1024 || max_user_connections | 0 || max_tmp_tables | 32 || max_write_lock_count | 4294967295 || myisam_recover_options | OFF || myisam_sort_buffer_size | 8388608 || net_buffer_length | 16384 || net_read_timeout | 30 || net_retry_count | 10 || net_write_timeout | 60 || open_files_limit | 0 || pid_file | c:\mysql\data\workstation.pid || port | 3306 || protocol_version | 10 || record_buffer | 131072 || query_buffer_size | 0 || safe_show_database | OFF || server_id | 0 || skip_locking | ON || skip_networking | OFF || skip_show_database | OFF || slow_launch_time | 2 || socket | MySQL || sort_buffer | 2097144 || table_cache | 64 || table_type | MYISAM || thread_cache_size | 0 || thread_stack | 65536 || transaction_isolation | READ-COMMITTED || timezone | Westeuropõische Sommerzeit || tmp_table_size | 1048576 || tmpdir | \ || version | 3.23.36 || wait_timeout | 28800 |+-------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+timezone:i have seen the following values'CEST''W. Europe Daylight Time''Westeuropõische Sommerzeit' i think that the 'õ' was a 'ä' in the database but was spitted outincorrectly in my telnet session.this makes it hard to find out the used timezone. not for a human, but for a peace of code.this method uses the 'SHOW VARIABLES' syntax.

Parameter
string $key = >>NULL,<<
the key (name) of the var you want the value. not case sensitive. if not set or set to NULL, an associative array holding all keys/values will be returned.