[ Index ]
 

Code source de PHPonTrax 2.6.6-svn

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/test/mockDB/ -> DB.php (sommaire)

File for mock DB class This file has the same name as the file holding the {@link http://pear.php.net/package/DB PEAR DB class}. To use the mock DB, put this file in the PHP include path ahead of the PEAR library, so that any class which requires DB.php will load this version.

Author: Walt Haas <haas@xmission.com>
Copyright: (c) Walter O. Haas 2006
License: http://opensource.org/licenses/gpl-license.php GNU Public License
Version: $Id: DB.php 198 2006-04-20 16:20:30Z haas $
Poids: 3324 lignes (121 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 6 classes

DB:: (8 méthodes):
  factory()
  connect()
  apiVersion()
  isError()
  isConnection()
  isManip()
  errorMessage()
  parseDSN()

DB_common:: (49 méthodes):
  DB_common()
  __sleep()
  __wakeup()
  __toString()
  quoteIdentifier()
  quoteSmart()
  escapeSimple()
  provides()
  setFetchMode()
  setOption()
  getOption()
  prepare()
  autoPrepare()
  autoExecute()
  buildManipSQL()
  execute()
  executeEmulateQuery()
  executeMultiple()
  freePrepared()
  modifyQuery()
  modifyLimitQuery()
  expect_query()
  expect_queries()
  tally_queries()
  query()
  limitQuery()
  getOne()
  getRow()
  getCol()
  getAssoc()
  getAll()
  autoCommit()
  commit()
  rollback()
  numRows()
  affectedRows()
  getSequenceName()
  nextId()
  createSequence()
  dropSequence()
  raiseError()
  errorNative()
  errorCode()
  errorMessage()
  tableInfo()
  getListOf()
  getSpecialQuery()
  _rtrimArrayValues()
  _convertNullArrayValuesToEmpty()

DB_Error:: (1 méthode):
  DB_Error()

DB_result:: (10 méthodes):
  DB_result()
  setOption()
  fetchRow()
  fetchInto()
  numCols()
  numRows()
  nextResult()
  free()
  getQuery()
  getRowCounter()

DB_row:: (1 méthode):
  DB_row()

DB_mysql:: (25 méthodes):
  DB_mysql()
  connect()
  disconnect()
  simpleQuery()
  nextResult()
  fetchInto()
  freeResult()
  numCols()
  numRows()
  autoCommit()
  commit()
  rollback()
  affectedRows()
  nextId()
  createSequence()
  dropSequence()
  _BCsequence()
  quoteIdentifier()
  escapeSimple()
  modifyQuery()
  modifyLimitQuery()
  mysqlRaiseError()
  errorNative()
  tableInfo()
  getSpecialQuery()


Classe: DB  - X-Ref

Mock DB class for testing

This class is a mock version of the
{@link http://pear.php.net/package/DB PEAR DB class}.  It is
intended to provide the same interface as the real DB class, plus
a small database sufficient to test software.
factory($type, $options = false)   X-Ref
Create a new DB object for the specified database type but don't
connect to the database

param: string $type     the database type (eg "mysql")
param: array  $options  an associative array of option names and values
return: object  a new DB object.  A DB_Error object on failure.

connect($dsn, $options = array()   X-Ref
Create a new DB object including a connection to the specified database

param: mixed $dsn      the string "data source name" or array in the
param: array $options  an associative array of option names and values
return: object  a new DB object.  A DB_Error object on failure.

apiVersion()   X-Ref
Return the DB API version

return: string  the DB API version number

isError($value)   X-Ref
Determines if a variable is a DB_Error object

param: mixed $value  the variable to check
return: bool  whether $value is DB_Error object

isConnection($value)   X-Ref
Determines if a value is a DB_<driver> object

param: mixed $value  the value to test
return: bool  whether $value is a DB_<driver> object

isManip($query)   X-Ref
Tell whether a query is a data manipulation or data definition query

param: string $query  the query
return: boolean  whether $query is a data manipulation query

errorMessage($value)   X-Ref
Return a textual error message for a DB error code

param: integer $value  the DB error code
return: string  the error message or false if the error code was

parseDSN($dsn)   X-Ref
Parse a data source name

param: string $dsn Data Source Name to be parsed
return: array an associative array with the following keys:

Classe: DB_common  - X-Ref

Mock DB_common for testing

DB_common()   X-Ref
This constructor calls <kbd>$this->PEAR('DB_Error')</kbd>

return: void

__sleep()   X-Ref
Automatically indicates which properties should be saved
when PHP's serialize() function is called

return: array  the array of properties names that should be saved

__wakeup()   X-Ref
Automatically reconnects to the database when PHP's unserialize()
function is called

return: void

__toString()   X-Ref
Automatic string conversion for PHP 5

return: string  a string describing the current PEAR DB object

quoteIdentifier($str)   X-Ref
Quotes a string so it can be safely used as a table or column name

param: string $str  the identifier name to be quoted
return: string  the quoted identifier

quoteSmart($in)   X-Ref
Formats input so it can be safely used in a query


escapeSimple($str)   X-Ref
Escapes a string according to the current DBMS's standards

param: string $str  the string to be escaped
return: string  the escaped string

provides($feature)   X-Ref
Tells whether the present driver supports a given feature

param: string $feature  the feature you're curious about
return: bool  whether this driver supports $feature

setFetchMode($fetchmode, $object_class = 'stdClass')   X-Ref
Sets the fetch mode that should be used by default for query results

param: integer $fetchmode    DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC
param: string $object_class  the class name of the object to be returned

setOption($option, $value)   X-Ref
Sets run-time configuration options for PEAR DB

param: string $option option name
param: mixed  $value value for the option
return: int  DB_OK on success.  A DB_Error object on failure.

getOption($option)   X-Ref
Returns the value of an option

param: string $option  the option name you're curious about
return: mixed  the option's value

prepare($query)   X-Ref
Prepares a query for multiple execution with execute()

param: string $query  the query to be prepared
return: mixed  DB statement resource on success. A DB_Error object

autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT,$where = false)   X-Ref
Automaticaly generates an insert or update query and pass it to
prepare()

param: string $table         the table name
param: array  $table_fields  the array of field names
param: int    $mode          a type of query to make:
param: string $where         for update queries: the WHERE clause to
return: resource  the query handle

autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT,$where = false)   X-Ref
Automaticaly generates an insert or update query and call prepare()
and execute() with it

param: string $table         the table name
param: array  $fields_values the associative array where $key is a
param: int    $mode          a type of query to make:
param: string $where         for update queries: the WHERE clause to
return: mixed  a new DB_result object for successful SELECT queries

buildManipSQL($table, $table_fields, $mode, $where = false)   X-Ref
Produces an SQL query string for autoPrepare()

param: string $table         the table name
param: array  $table_fields  the array of field names
param: int    $mode          a type of query to make:
param: string $where         for update queries: the WHERE clause to
return: string  the sql query for autoPrepare()

execute($stmt, $data = array()   X-Ref
Executes a DB statement prepared with prepare()

param: resource $stmt  a DB statement resource returned from prepare()
param: mixed    $data  array, string or numeric data to be used in
return: mixed  a new DB_result object for successful SELECT queries

executeEmulateQuery($stmt, $data = array()   X-Ref
Emulates executing prepared statements if the DBMS not support them

param: resource $stmt  a DB statement resource returned from execute()
param: mixed    $data  array, string or numeric data to be used in
return: mixed  a string containing the real query run when emulating

executeMultiple($stmt, $data)   X-Ref
Performs several execute() calls on the same statement handle

param: resource $stmt  query handle from prepare()
param: array    $data  numeric array containing the
return: int  DB_OK on success.  A DB_Error object on failure.

freePrepared($stmt, $free_resource = true)   X-Ref
Frees the internal resources associated with a prepared query

param: resource $stmt           the prepared statement's PHP resource
param: bool     $free_resource  should the PHP resource be freed too?
return: bool  TRUE on success, FALSE if $result is invalid

modifyQuery($query)   X-Ref
Changes a query string for various DBMS specific reasons

param: string $query  the query string to modify
return: string  the modified query string

modifyLimitQuery($query, $from, $count, $params = array()   X-Ref
Adds LIMIT clauses to a query string according to current DBMS standards

param: string $query   the query to modify
param: int    $from    the row to start to fetching (0 = the first row)
param: int    $count   the numbers of rows to fetch
param: mixed  $params  array, string or numeric data to be used in
return: string  the query string with LIMIT clauses added

expect_query($expected, $result)   X-Ref
Set expected query and return

This is a test routine that does not exist in the PEAR DB package.
param: string $expected Expected query
param: string $result Result to be returned when expected

expect_queries($list)   X-Ref
Set list of expected queries and returns

This is a test routine that does not exist in the PEAR DB package.
param: string $list Expected queries and returns

tally_queries()   X-Ref
Verify that all expected queries have been received

This is a test routine that does not exist in the PEAR DB package.

query($query, $params = array()   X-Ref
Sends a query to the database server

param: string $query   the SQL query or the statement to prepare
param: mixed  $params  array, string or numeric data to be used in
return: mixed  a new DB_result object for successful SELECT queries

limitQuery($query, $from, $count, $params = array()   X-Ref
Generates and executes a LIMIT query

param: string $query   the query
param: intr   $from    the row to start to fetching (0 = the first row)
param: int    $count   the numbers of rows to fetch
param: mixed  $params  array, string or numeric data to be used in
return: mixed  a new DB_result object for successful SELECT queries

getOne($query, $params = array()   X-Ref
Fetches the first column of the first row from a query result

param: string $query   the SQL query
param: mixed  $params  array, string or numeric data to be used in
return: mixed  the returned value of the query.

getRow($query, $params = array()   X-Ref
Fetches the first row of data returned from a query result

param: string $query   the SQL query
param: mixed  $params  array, string or numeric data to be used in
param: int $fetchmode  the fetch mode to use
return: array  the first row of results as an array.

getCol($query, $col = 0, $params = array()   X-Ref
Fetches a single column from a query result and returns it as an
indexed array

param: string $query   the SQL query
param: mixed  $col     which column to return (integer [column number,
param: mixed  $params  array, string or numeric data to be used in
return: array  the results as an array.  A DB_Error object on failure.

getAssoc($query, $force_array = false, $params = array()   X-Ref
Fetches an entire query result and returns it as an
associative array using the first column as the key

param: string $query        the SQL query
param: bool   $force_array  used only when the query returns
param: mixed  $params       array, string or numeric data to be used in
param: int   $fetchmode     the fetch mode to use
param: bool  $group         if true, the values of the returned array
return: array  the associative array containing the query results.

getAll($query, $params = array()   X-Ref
Fetches all of the rows from a query result

param: string $query      the SQL query
param: mixed  $params     array, string or numeric data to be used in
param: int    $fetchmode  the fetch mode to use:
return: array  the nested array.  A DB_Error object on failure.

autoCommit($onoff = false)   X-Ref
Enables or disables automatic commits

param: bool $onoff  true turns it on, false turns it off
return: int  DB_OK on success.  A DB_Error object if the driver

commit()   X-Ref
Commits the current transaction

return: int  DB_OK on success.  A DB_Error object on failure.

rollback()   X-Ref
Reverts the current transaction

return: int  DB_OK on success.  A DB_Error object on failure.

numRows($result)   X-Ref
Determines the number of rows in a query result

param: resource $result  the query result idenifier produced by PHP
return: int  the number of rows.  A DB_Error object on failure.

affectedRows()   X-Ref
Determines the number of rows affected by a data maniuplation query

0 is returned for queries that don't manipulate data.

return: int  the number of rows.  A DB_Error object on failure.

getSequenceName($sqn)   X-Ref
Generates the name used inside the database for a sequence

param: string $sqn  the sequence's public name
return: string  the sequence's name in the backend

nextId($seq_name, $ondemand = true)   X-Ref
Returns the next free id in a sequence

param: string  $seq_name  name of the sequence
param: boolean $ondemand  when true, the seqence is automatically
return: int  the next id number in the sequence.

createSequence($seq_name)   X-Ref
Creates a new sequence

param: string $seq_name  name of the new sequence
return: int  DB_OK on success.  A DB_Error object on failure.

dropSequence($seq_name)   X-Ref
Deletes a sequence

param: string $seq_name  name of the sequence to be deleted
return: int  DB_OK on success.  A DB_Error object on failure.

raiseError($code = DB_ERROR, $mode = null, $options = null,$userinfo = null, $nativecode = null)   X-Ref
Communicates an error and invoke error callbacks, etc

Basically a wrapper for PEAR::raiseError without the message string.

param: mixed   integer error code, or a PEAR error object (all
param: int     error mode, see PEAR_Error docs
param: mixed   if error mode is PEAR_ERROR_TRIGGER, this is the
param: string  extra debug information.  Defaults to the last
param: mixed   native error code, integer or string depending the
return: object  the PEAR_Error object

errorNative()   X-Ref
Gets the DBMS' native error code produced by the last query

return: mixed  the DBMS' error code.  A DB_Error object on failure.

errorCode($nativecode)   X-Ref
Maps native error codes to DB's portable ones

Uses the <var>$errorcode_map</var> property defined in each driver.

param: string|int $nativecode  the error code returned by the DBMS
return: int  the portable DB error code.  Return DB_ERROR if the

errorMessage($dbcode)   X-Ref
Maps a DB error code to a textual message

param: integer $dbcode  the DB error code
return: string  the error message corresponding to the error code

tableInfo($result, $mode = null)   X-Ref
Returns information about a table or a result set

param: object|string  $result  DB_result object from a query or a
param: int  $mode   either unused or one of the tableInfo modes:
return: array  an associative array with the information requested.

getListOf($type)   X-Ref
Lists internal database information

param: string $type  type of information being sought.
return: array  an array listing the items sought.

getSpecialQuery($type)   X-Ref
Obtains the query string needed for listing a given type of objects

param: string $type  the kind of objects you want to retrieve
return: string  the SQL query string or null if the driver doesn't

_rtrimArrayValues(&$array)   X-Ref
Right-trims all strings in an array

param: array $array  the array to be trimmed (passed by reference)
return: void

_convertNullArrayValuesToEmpty(&$array)   X-Ref
Converts all null values in an array to empty strings

param: array  $array  the array to be de-nullified (passed by reference)
return: void

Classe: DB_Error  - X-Ref

Mock DB_Error

DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,$level = E_USER_NOTICE, $debuginfo = null)   X-Ref
DB_Error constructor

param: mixed $code       DB error code, or string with error message
param: int   $mode       what "error mode" to operate in
param: int   $level      what error level to use for $mode &
param: mixed $debuginfo  additional debug info, such as the last query

Classe: DB_result  - X-Ref

Mock DB_result

DB_result(&$dbh, $result, $options = array()   X-Ref
This constructor sets the object's properties

param: object   &$dbh     the DB object reference
param: resource $result   the result resource id
param: array    $options  an associative array with result options
return: void

setOption($key, $value = null)   X-Ref
Set options for the DB_result object

param: string $key    the option to set
param: mixed  $value  the value to set the option to
return: void

fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)   X-Ref
Fetch a row of data and return it by reference into an array

param: int $fetchmode  the constant indicating how to format the data
param: int $rownum     the row number to fetch (index starts at 0)
return: mixed  an array or object containing the row's data,

fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)   X-Ref
Fetch a row of data into an array which is passed by reference

param: array &$arr       the variable where the data should be placed
param: int   $fetchmode  the constant indicating how to format the data
param: int   $rownum     the row number to fetch (index starts at 0)
return: mixed  DB_OK if a row is processed, NULL when the end of the

numCols()   X-Ref
Get the the number of columns in a result set

return: int  the number of columns.  A DB_Error object on failure.

numRows()   X-Ref
Get the number of rows in a result set

return: int  the number of rows.  A DB_Error object on failure.

nextResult()   X-Ref
Get the next result if a batch of queries was executed

return: bool  true if a new result is available or false if not

free()   X-Ref
Frees the resources allocated for this result set

return: bool  true on success.  A DB_Error object on failure.

getQuery()   X-Ref
Determine the query string that created this result

return: string  the query string

getRowCounter()   X-Ref
Tells which row number is currently being processed

return: integer  the current row being looked at.  Starts at 1.

Classe: DB_row  - X-Ref

Mock DB_row

DB_row(&$arr)   X-Ref
The constructor places a row's data into properties of this object

param: array  the array containing the row's data
return: void

Classe: DB_mysql  - X-Ref

Mock DB_mysql class

DB_mysql()   X-Ref
This constructor calls <kbd>$this->DB_common()</kbd>

return: void

connect($dsn, $persistent = false)   X-Ref
Connect to the database server, log in and open the database

param: array $dsn         the data source name
param: bool  $persistent  should the connection be persistent?
return: int  DB_OK on success. A DB_Error object on failure.

disconnect()   X-Ref
Disconnects from the database server

return: bool  TRUE on success, FALSE on failure

simpleQuery($query)   X-Ref
Sends a query to the database server

Generally uses mysql_query().  If you want to use
mysql_unbuffered_query() set the "result_buffering" option to 0 using
setOptions().  This option was added in Release 1.7.0.

param: string  the SQL query string
return: mixed  + a PHP result resrouce for successful SELECT queries

nextResult($result)   X-Ref
Move the internal mysql result pointer to the next available result

This method has not been implemented yet.

param: a valid sql result resource
return: false

fetchInto($result, &$arr, $fetchmode, $rownum = null)   X-Ref
Places a row from the result set into the given array

param: resource $result    the query result resource
param: array    $arr       the referenced array to put the data in
param: int      $fetchmode how the resulting array should be indexed
param: int      $rownum    the row number to fetch (0 = first row)
return: mixed  DB_OK on success, NULL when the end of a result set is

freeResult($result)   X-Ref
Deletes the result set and frees the memory occupied by the result set

This method is not meant to be called directly.  Use
DB_result::free() instead.  It can't be declared "protected"
because DB_result is a separate object.

param: resource $result  PHP's query result resource
return: bool  TRUE on success, FALSE if $result is invalid

numCols($result)   X-Ref
Gets the number of columns in a result set

This method is not meant to be called directly.  Use
DB_result::numCols() instead.  It can't be declared "protected"
because DB_result is a separate object.

param: resource $result  PHP's query result resource
return: int  the number of columns.  A DB_Error object on failure.

numRows($result)   X-Ref
Gets the number of rows in a result set

This method is not meant to be called directly.  Use
DB_result::numRows() instead.  It can't be declared "protected"
because DB_result is a separate object.

param: resource $result  PHP's query result resource
return: int  the number of rows.  A DB_Error object on failure.

autoCommit($onoff = false)   X-Ref
Enables or disables automatic commits

param: bool $onoff  true turns it on, false turns it off
return: int  DB_OK on success.  A DB_Error object if the driver

commit()   X-Ref
Commits the current transaction

return: int  DB_OK on success.  A DB_Error object on failure.

rollback()   X-Ref
Reverts the current transaction

return: int  DB_OK on success.  A DB_Error object on failure.

affectedRows()   X-Ref
Determines the number of rows affected by a data maniuplation query

0 is returned for queries that don't manipulate data.

return: int  the number of rows.  A DB_Error object on failure.

nextId($seq_name, $ondemand = true)   X-Ref
Returns the next free id in a sequence

param: string  $seq_name  name of the sequence
param: boolean $ondemand  when true, the seqence is automatically
return: int  the next id number in the sequence.

createSequence($seq_name)   X-Ref
Creates a new sequence

param: string $seq_name  name of the new sequence
return: int  DB_OK on success.  A DB_Error object on failure.

dropSequence($seq_name)   X-Ref
Deletes a sequence

param: string $seq_name  name of the sequence to be deleted
return: int  DB_OK on success.  A DB_Error object on failure.

_BCsequence($seqname)   X-Ref
Backwards compatibility with old sequence emulation implementation
(clean up the dupes)

param: string $seqname  the sequence name to clean up
return: bool  true on success.  A DB_Error object on failure.

quoteIdentifier($str)   X-Ref
Quotes a string so it can be safely used as a table or column name

MySQL can't handle the backtick character (<kbd>`</kbd>) in
table or column names.

param: string $str  identifier name to be quoted
return: string  quoted identifier string

escapeSimple($str)   X-Ref
Escapes a string according to the current DBMS's standards

param: string $str  the string to be escaped
return: string  the escaped string

modifyQuery($query)   X-Ref
Changes a query string for various DBMS specific reasons

This little hack lets you know how many rows were deleted
when running a "DELETE FROM table" query.  Only implemented
if the DB_PORTABILITY_DELETE_COUNT portability option is on.

param: string $query  the query string to modify
return: string  the modified query string

modifyLimitQuery($query, $from, $count, $params = array()   X-Ref
Adds LIMIT clauses to a query string according to current DBMS standards

param: string $query   the query to modify
param: int    $from    the row to start to fetching (0 = the first row)
param: int    $count   the numbers of rows to fetch
param: mixed  $params  array, string or numeric data to be used in
return: string  the query string with LIMIT clauses added

mysqlRaiseError($errno = null)   X-Ref
Produces a DB_Error object regarding the current problem

param: int $errno  if the error is being manually raised pass a
return: object  the DB_Error object

errorNative()   X-Ref
Gets the DBMS' native error code produced by the last query

return: int  the DBMS' error code

tableInfo($result, $mode = null)   X-Ref
Returns information about a table or a result set

param: object|string  $result  DB_result object from a query or a
param: int            $mode    a valid tableInfo mode
return: array  an associative array with the information requested.

getSpecialQuery($type)   X-Ref
Obtains the query string needed for listing a given type of objects

param: string $type  the kind of objects you want to retrieve
return: string  the SQL query string or null if the driver doesn't



Généré le : Sun Feb 25 20:04:38 2007 par Balluche grâce à PHPXref 0.7