Static Public Member Functions | Private Member Functions | Static Private Attributes
c_comdef_dbsingleton Class Reference

This class provides a genericized interface to the PHP PDO toolkit. It is a completely static class. More...

List of all members.

Static Public Member Functions

static init ($driver, $host, $database, $user=null, $password=null, $charset=null)
 Initializes connection param class members.
static connect ()
 Create internal PDO object thus connecting to database using connection param class members (passed in from previous call to c_comdef_dbsingleton::init())
static isConnected ()
 Returns whether internal PDO object is instantiated and thus connected.
static pdoInstance ($do_connect=false)
 Provides access to internal PDO object in case this classes functionality is not enough.
static preparedQuery ($sql, $params=array(), $fetchKeyPair=false)
 Wrapper for preparing and executing a PDOStatement that returns a resultset e.g. SELECT SQL statements.
static preparedExec ($sql, $params=array())
 Wrapper for preparing and executing a PDOStatement that does not return a resultset e.g. INSERT or UPDATE SQL statements.
static lastInsertId ()
 Wrapper for PDO::lastInsertId()

Private Member Functions

 __construct ()
 Private constructor (prevents direct creation of object)

Static Private Attributes

static $pdo = null
 Internal PDO object.
static $driver = null
 Connection database driver type param.
static $host = null
 Connection host param.
static $database = null
 Connection database param.
static $user = null
 Connection user param.
static $password = null
 Connection password param.
static $charset = null
 Connection charset param.
static $fetchMode = PDO::FETCH_ASSOC
 Default fetch mode for internal PDOStatements.

Detailed Description

This class provides a genericized interface to the PHP PDO toolkit. It is a completely static class.


Constructor & Destructor Documentation

c_comdef_dbsingleton::__construct ( ) [private]

Private constructor (prevents direct creation of object)


Member Function Documentation

static c_comdef_dbsingleton::connect ( ) [static]

Create internal PDO object thus connecting to database using connection param class members (passed in from previous call to c_comdef_dbsingleton::init())

Will destroy previous connection (if one exists) before reconnecting

Exceptions:
Exceptionthrown if internal PDO object cannot be created e.g. wrong connection param(s)

For security purposes, once we connect, we get rid of all the info, and a new init needs to be called.

static c_comdef_dbsingleton::init ( driver,
host,
database,
user = null,
password = null,
charset = null 
) [static]

Initializes connection param class members.

Must be called BEFORE any attempts to connect to or query a database.

Will destroy previous connection (if one exists).

Parameters:
driverdatabase server type (ex: 'mysql')
hostdatabase server host
databasedatabase name
useruser, optional
passwordpassword, optional
charsetconnection charset, optional

Referenced by c_comdef_server::__construct(), DB_Connect_and_Upgrade(), and SetPageFive().

static c_comdef_dbsingleton::isConnected ( ) [static]

Returns whether internal PDO object is instantiated and thus connected.

Returns:
true if connected.
static c_comdef_dbsingleton::lastInsertId ( ) [static]

Wrapper for PDO::lastInsertId()

Returns:
the ID of the last INSERT
Exceptions:
Exceptionthrown if internal PDO object not instantiated
static c_comdef_dbsingleton::pdoInstance ( do_connect = false) [static]

Provides access to internal PDO object in case this classes functionality is not enough.

Returns:
the PDO object
Exceptions:
Exceptionthrown if internal PDO object not instantiated
Parameters:
do_connectSet this to true to force a connection if one does not yet exist. Default is false.

Referenced by c_comdef_server::GetMeetings().

static c_comdef_dbsingleton::preparedExec ( sql,
params = array() 
) [static]

Wrapper for preparing and executing a PDOStatement that does not return a resultset e.g. INSERT or UPDATE SQL statements.

See PDO documentation about prepared queries.

If there isn't already a database connection, it will "lazy load" the connection.

Exceptions:
Exceptionthrown if internal PDO exception is thrown
Returns:
true if execution is successful.
Parameters:
sqlsame as kind provided to PDO::prepare()
paramssame as kind provided to PDO::prepare()

Referenced by DB_Connect_and_Upgrade(), c_comdef_change::DeleteFromDB(), c_comdef_user::DeleteFromDB_NoRecord(), c_comdef_service_body::DeleteFromDB_NoRecord(), c_comdef_meeting::DeleteFromDB_NoRecord(), c_comdef_format::DeleteFromDB_NoRecord(), c_comdef_server::GetNewMeetingID(), SetPageFive(), c_comdef_user::UpdateToDB(), c_comdef_service_body::UpdateToDB(), c_comdef_meeting::UpdateToDB(), c_comdef_format::UpdateToDB(), and c_comdef_change::UpdateToDB().

static c_comdef_dbsingleton::preparedQuery ( sql,
params = array(),
fetchKeyPair = false 
) [static]

Wrapper for preparing and executing a PDOStatement that returns a resultset e.g. SELECT SQL statements.

Returns a multidimensional array depending on internal fetch mode setting (self::$fetchMode) See PDO documentation about prepared queries.

If there isn't already a database connection, it will "lazy load" the connection.

Fetching key pairs- when $fetchKeyPair is set to TRUE, it will force the returned array to be a one-dimensional array indexed on the first column in the query. Note- query may contain only two columns or an exception/error is thrown. See PDO::PDO::FETCH_KEY_PAIR for more details

Returns:
associative array of results.
Exceptions:
Exceptionthrown if internal PDO exception is thrown
Parameters:
sqlsame as kind provided to PDO::prepare()
paramssame as kind provided to PDO::prepare()
fetchKeyPairSee description in method documentation

Referenced by c_comdef_server::DoesMeetingExist(), c_comdef_meeting::GetAllMeetingKeys(), c_comdef_server::GetChangesFromSQL(), c_comdef_meeting::GetDataTableTemplate(), c_comdef_meeting::GetLongDataTableTemplate(), c_comdef_server::GetMeetingsFromSQL(), c_comdef_server::GetNewMeetingID(), c_comdef_server::GetOneFormat(), c_comdef_server::GetOneMeeting(), c_comdef_server::GetOneUser(), c_comdef_server::HuntForRadius(), c_comdef_server::IsFormatKeyUnique(), c_comdef_meeting::process_meeting_row(), c_comdef_server::ReadFormats(), c_comdef_server::ReadServiceBodies(), c_comdef_server::ReadServiceIDs(), c_comdef_server::ReadUsers(), c_comdef_user::RestoreFromDB(), c_comdef_service_body::RestoreFromDB(), c_comdef_meeting::RestoreFromDB(), c_comdef_format::RestoreFromDB(), c_comdef_change::RestoreFromDB(), c_comdef_user::UpdateToDB(), c_comdef_service_body::UpdateToDB(), and c_comdef_change::UpdateToDB().


Member Data Documentation

c_comdef_dbsingleton::$charset = null [static, private]

Connection charset param.

c_comdef_dbsingleton::$database = null [static, private]

Connection database param.

c_comdef_dbsingleton::$driver = null [static, private]

Connection database driver type param.

c_comdef_dbsingleton::$fetchMode = PDO::FETCH_ASSOC [static, private]

Default fetch mode for internal PDOStatements.

c_comdef_dbsingleton::$host = null [static, private]

Connection host param.

c_comdef_dbsingleton::$password = null [static, private]

Connection password param.

c_comdef_dbsingleton::$pdo = null [static, private]

Internal PDO object.

c_comdef_dbsingleton::$user = null [static, private]

Connection user param.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Enumerations