Class: database

Source Location: /database.php

Class Overview [line 49]


Author(s):

Version:

Copyright:

Variables

Constants

Methods


Inherited Variables

Inherited Constants

Inherited Methods



Class Details

[ Top ]


Class Variables


Class Methods

__construct

database __construct( [connInfo $connInfo = null], [connType $connType = "mysql"])

[line 104]

This is the two argument constructor for the database connection object. This will create the database connection if possible or if it fails it will set the 'connected' flag to false indicating that we aren't connected to the database.

Tags:

  • access - public

Parameters:

  • connInfo $connInfo - The connection information about how to connect to the database. This value should be an array setup in the following fashion. array ( "host" => "hostname", "name" => "database_name", "user" => "username", "pass" => "password" ) If this array is NULL or any of the elements are missing, then they will be defaulted to the values as specified in the constructor.
  • connType $connType - The type of database that we are connecting to

[ Top ]

commit

TRUE commit( )

[line 728]

This function is used in order to commit all of the queries which were executed on the database to the database.

Tags:

  • return - on success, FALSE on failure
  • access - public

Parameters:

[ Top ]

freeResults

void freeResults( res $res)

[line 189]

This function is used in order to free the results from the query that is passed in as the argument.

Tags:

  • access - public

Parameters:

  • res $res - The result set to clear

[ Top ]

getArray

The getArray( res $res)

[line 547]

This function is used in order to retrieve an associative array from the database statement.

Tags:

  • return - associative array retrieved from the database query or NULL if if value passed in was NULL
  • access - public

Parameters:

  • res $res - The result that the 'query' function returned

[ Top ]

getBoth

The getBoth( res $res)

[line 601]

This function is used in order to retrieve both the associative array and the indexed array from the database statement.

Tags:

  • return - associative array and the indexed array retrieved from the database query or NULL if value passed in was NULL
  • access - public

Parameters:

  • res $res - The result that the 'query' function returned

[ Top ]

getDatabaseConnection

The getDatabaseConnection( )

[line 632]

This function is used in order to retrieve the actual database connection that was created on instantiation of the object.

Tags:

  • return - database connection object
  • access - public

Parameters:

[ Top ]

getLogging

TRUE getLogging( )

[line 828]

This function is used in order to determine if we are keeping logs of all of the queries that occur.

Tags:

  • return - if we are logging all of the queries, FALSE if we are not
  • access - public

Parameters:

[ Top ]

getNumber

The getNumber( res $res)

[line 584]

This function is used in order to retrieve an indexed array from the database statement.

Tags:

  • return - indexed array retrieved from the database query or NULL if value passed in was NULL
  • access - public

Parameters:

  • res $res - The result that the 'query' function returned

[ Top ]

getTotalTime

The getTotalTime( [$dp $dp = null])

[line 775]

This function is used in order to retrieve the total amount of time it took to execute all of the queries on the database.

Tags:

  • return - total amount of time taken to execute all of the database queries in microseconds.
  • access - public

Parameters:

  • $dp $dp - How many decimal places to round the number to, ignore this parameter if you do not want to round the number, otherwise if invalid then NULL will be returned.

[ Top ]

numRows

NULL numRows( res $res)

[line 523]

This function is used in order to return the number of rows for a given query.

Tags:

  • return - if the parameter is invalid or the number of rows that is with the database statement
  • access - public

Parameters:

  • res $res - The statement that has been executed.

[ Top ]

printLog

void printLog( )

[line 858]

This function is used in order to display the log in a more useful manner.

This function will output the information directly onto the page.

Tags:

  • access - public

Parameters:

[ Top ]

query

This query( query $query, args1-X 1)

[line 238]

This function is the starting function for the query that is being run.

It will take in the query with the following values for the parameters and then insert the values in their corresponding spots after making sure that the data passed in matches the correct data type (based on regular expression).

The following are parameter types for the values:

  • %u - unsigned integer - ^[0-9]+$
  • %d - signed integer - ^[-+]?[0-9]+$
  • %p - decimal number - ^[-+]?[0-9]+(\.[0-9]+)?$
  • %s - string (no HTML permitted)
  • %h - string (HTML permitted)
  • %l - list of strings (comma separated) or an array (no HTML permitted)
  • %f - field
The number of arguments passed into this function is required to be directly related to the number of parameters included in the query. For example, if there are two parameters in the query then there should be three arguments for the function (one argument for the query and two arguments for the necessary parameters).

Example of how to use the parameters in a query: $db = new database (); //make the database connection
$result = $db -> query ( "SELECT * FROM `members` WHERE `id` = %u AND `username` = %s", $user_id, $username ); //Create the query
The query will validate the variable $user_id will be validated as an unsigned integer and the $username will be validated as a string.

Tags:

  • return - function will either return a PDO Statement which has been executed (if all validation is successful) or NULL NULL will be returned in the following cases:
    • No database connection
    • Too few arguments
    • Too many arguments
    • Invalid Data Type
    • Unknown Parameter Type
  • access - public

Parameters:

  • args1-X 1 - All of the corresponding values for the query (the number of these is based on however many parameters there are in the database query)
  • query $query - The query that we will be building on

[ Top ]

retrieveAllRows

An retrieveAllRows( res $res)

[line 617]

This function is used in order to retrieve all of the rows which were obtained by the database query.

Tags:

  • return - array of all of the results retrieved from the database
  • access - public

Parameters:

  • res $res - The result that the 'query' function returned

[ Top ]

retrieveLog

The retrieveLog( )

[line 849]

This function is used in order to retrieve the raw version of the log (the array that actually holds the log).

Tags:

  • return - array containing the actual log
  • access - public

Parameters:

[ Top ]

retrieveNumberOfQueries

The retrieveNumberOfQueries( )

[line 805]

This function is used in order to retrieve the number of queries which were executed on the database.

Tags:

  • return - number of successful queries executed on the database
  • access - public

Parameters:

[ Top ]

rollback

TRUE rollback( )

[line 685]

This function is used in order to rollback any queries which were executed on the database.

Tags:

  • return - on success, FALSE on failure
  • access - public

Parameters:

[ Top ]

setLogging

void setLogging( $value $value)

[line 815]

<em> This function is used in order to turn on/off the query logging functionality.

Tags:

  • access - public

Parameters:

  • $value $value - Either TRUE or FALSE depending if you want all queries to be logged (TRUE they will be, FALSE they will not be)

[ Top ]

setVerbose

void setVerbose( verbose $verbose)

[line 572]

This function is used in order to set whether or not verbose mode is on or off.

Tags:

  • access - public

Parameters:

  • verbose $verbose - TRUE if the verbose mode is to be turned on, FALSE otherwise

[ Top ]

startTransaction

TRUE startTransaction( )

[line 642]

This function is used in order to start a transaction so that the set of queries can be rolled back or committed at any time.

Tags:

  • return - on success, FALSE on failure
  • access - public

Parameters:

[ Top ]


Class Constants


Documentation generated on Fri, 22 May 2009 19:27:28 -0400 by phpDocumentor 1.4.1