Home / PHP Advanced Database Class / DB Class Reference


Public Member Functions

 DB ($base, $server, $user, $pass)
 query ($query, $debug=-1)
 execute ($query, $debug=-1)
 fetchNextObject ($result=NULL)
 numRows ($result=NULL)
 queryUniqueObject ($query, $debug=-1)
 queryUniqueValue ($query, $debug=-1)
 maxOf ($column, $table, $where)
 maxOfAll ($column, $table)
 countOf ($table, $where)
 countOfAll ($table)
 debugAndDie ($query)
 debug ($debug, $query, $result=NULL)
 debugQuery ($query, $reason="Debug")
 debugResult ($result)
 getExecTime ()
 getQueriesCount ()
 resetFetch ($result)
 lastInsertedId ()
 close ()
 getMicroTime ()

Public Attributes

 $defaultDebug = false
 $mtStart
 $nbQueries
 $lastResult

Detailed Description

A PHP class to access MySQL database with convenient methods in an object oriented way, and with a powerful debug system.
Licence: LGPL
Web site: http://slaout.linux62.org/
Version:
1.0
Author:
Sébastien Laoût (slaout@linux62.org)


Constructor & Destructor Documentation

DB::DB base,
server,
user,
pass
 

Connect to a MySQL database to be able to use the methods below.


Member Function Documentation

DB::close  ) 
 

Close the connexion with the database server.
It's usually unneeded since PHP do it automatically at script end.

DB::countOf table,
where
 

Get the count of rows in a table, with a condition.

Parameters:
$table The table where to compute the number of rows.
$where The condition before to compute the number or rows.
Returns:
The number of rows (0 or more).

DB::countOfAll table  ) 
 

Get the count of rows in a table.

Parameters:
$table The table where to compute the number of rows.
Returns:
The number of rows (0 or more).

DB::debug debug,
query,
result = NULL
 

Internal function to debug a MySQL query.
Show the query and output the resulting table if not NULL.

Parameters:
$debug The parameter passed to query() functions. Can be boolean or -1 (default).
$query The SQL query to debug.
$result The resulting table of the query, if available.

DB::debugAndDie query  ) 
 

Internal function to debug when MySQL encountered an error, even if debug is set to Off.

Parameters:
$query The SQL query to echo before diying.

DB::debugQuery query,
reason = "Debug"
 

Internal function to output a query for debug purpose.
Should be followed by a call to debugResult() or an echo of "</div>".

Parameters:
$query The SQL query to debug.
$reason The reason why this function is called: "Default Debug", "Debug" or "Error".

DB::debugResult result  ) 
 

Internal function to output a table representing the result of a query, for debug purpose.
Should be preceded by a call to debugQuery().

Parameters:
$result The resulting table of the query.

DB::execute query,
debug = -1
 

Do the same as query() but do not return nor store result.
Should be used for INSERT, UPDATE, DELETE...

Parameters:
$query The query.
$debug If true, it output the query and the resulting table.

DB::fetchNextObject result = NULL  ) 
 

Convenient method for mysql_fetch_object().

Parameters:
$result The ressource returned by query(). If NULL, the last result returned by query() will be used.
Returns:
An object representing a data row.

DB::getExecTime  ) 
 

Get how many time the script took from the begin of this object.

Returns:
The script execution time in seconds since the creation of this object.

DB::getMicroTime  ) 
 

Internal method to get the current time.

Returns:
The current time in seconds with microseconds (in float format).

DB::getQueriesCount  ) 
 

Get the number of queries executed from the begin of this object.

Returns:
The number of queries executed on the database server since the creation of this object.

DB::lastInsertedId  ) 
 

Get the id of the very last inserted row.

Returns:
The id of the very last inserted row (in any table).

DB::maxOf column,
table,
where
 

Get the maximum value of a column in a table, with a condition.

Parameters:
$column The column where to compute the maximum.
$table The table where to compute the maximum.
$where The condition before to compute the maximum.
Returns:
The maximum value (or NULL if result is empty).

DB::maxOfAll column,
table
 

Get the maximum value of a column in a table.

Parameters:
$column The column where to compute the maximum.
$table The table where to compute the maximum.
Returns:
The maximum value (or NULL if result is empty).

DB::numRows result = NULL  ) 
 

Get the number of rows of a query.

Parameters:
$result The ressource returned by query(). If NULL, the last result returned by query() will be used.
Returns:
The number of rows of the query (0 or more).

DB::query query,
debug = -1
 

Query the database.

Parameters:
$query The query.
$debug If true, it output the query and the resulting table.
Returns:
The result of the query, to use with fetchNextObject().

DB::queryUniqueObject query,
debug = -1
 

Get the result of the query as an object. The query should return a unique row.
Note: no need to add "LIMIT 1" at the end of your query because the method will add that (for optimisation purpose).

Parameters:
$query The query.
$debug If true, it output the query and the resulting row.
Returns:
An object representing a data row (or NULL if result is empty).

DB::queryUniqueValue query,
debug = -1
 

Get the result of the query as value. The query should return a unique cell.
Note: no need to add "LIMIT 1" at the end of your query because the method will add that (for optimisation purpose).

Parameters:
$query The query.
$debug If true, it output the query and the resulting value.
Returns:
A value representing a data cell (or NULL if result is empty).

DB::resetFetch result  ) 
 

Go back to the first element of the result line.

Parameters:
$result The resssource returned by a query() function.


Member Data Documentation

DB::$defaultDebug = false
 

Put this variable to true if you want ALL queries to be debugged by default:

DB::$lastResult
 

INTERNAL: The last result ressource of a query().

DB::$mtStart
 

INTERNAL: The start time, in miliseconds.

DB::$nbQueries
 

INTERNAL: The number of executed queries.


The documentation for this class was generated from the following file:
Generated on Tue Mar 29 23:09:34 2005 for db.class.php by doxygen 1.3.3