PHPDevShell 3.1.3-Stable
PHP OOP RAD Development Framework
PHPDS_db Class Reference
Inheritance diagram for PHPDS_db:
PHPDS_dependant

Public Member Functions

 __construct ($dependance)
 connect ()
 connector ($connector=null)
 newQuery ($query)
 sqlQuery ($query)
 invokeQuery ($query_name)
 invokeQueryWith ($query_name, $params)
 makeQuery ($query_name)
 startTransaction ()
 endTransaction ()
 protect ($param)
 protectArray (array $a, $quote= '')
 tableExist ($table)
 countRows ($table_name, $column=false)
 logMenuAccess ()
 logThis ()
 getRoles ($user_id=false, $return_array=false)
 getGroups ($user_id=false, $return_array=false, $alias_only=false)
 roleExist ($role_id)
 groupExist ($group_id)
 belongsToRole ($user_id=false, $user_role)
 belongsToGroup ($user_id=false, $user_group)
 setRoleQuery ($query_request, $query_root_request=false)
 setGroupQuery ($query_request, $query_root_request=false)
 settingsPrefix ($custom_prefix=false)
 writeSettings ($write_settings, $custom_prefix= '', $notes=array())
 deleteSettings ($settings_to_delete=false, $custom_prefix=false)
 getSettings ($settings_required=false, $custom_prefix=false)
 getEssentialSettings ()
 doesRecordExist ($table_name, $search_column_names, $search_field_values, $column_name_for_exclusion=false, $exclude_field_value=false)
 selectQuick ($from_table_name, $select_column_name, $where_column_name, $is_equal_to_column_value)
 deleteQuick ($from_table_name, $where_column_name, $is_equal_to_column_value, $return_column_value=false)
 nameOfNewCopy ($table_name, $name_field, $orig_name)
 installedPlugins ()
 connectCacheServer ()
 cacheWrite ($unique_key, $cache_data, $compress=false, $timeout=false)
 cacheRead ($unique_key)
 cacheClear ($unique_key=false)
 cacheEmpty ($unique_key)

Data Fields

 $server
 $dbUsername
 $dbPassword
 $dbName
 $connection
 $memcache
 $logArray
 $countQueries = -2
 $pluginsInstalled
 $pluginLogo
 $essentialSettings
 $displaySqlInError = false
 $result

Protected Attributes

 $connector
 $connectors
 $defaultQuery

Detailed Description

This is a new version of one the Big5: the db class

This new version supports connectors and queries class and should be compatible with the old one

Version:
1.0
Date:
20100219
Author:
greg

Constructor & Destructor Documentation

__construct ( dependance)

Constructor.


Member Function Documentation

belongsToGroup ( user_id = false,
user_group 
)

Check if user belongs to given group. Returns true if user belongs to user group.

Deprecated:
Parameters:
integer$user_id
integer$user_group
Returns:
boolean Returns true if user belongs to user group.
Author:
Jason Schoeman <titan@phpdevshell.org>
belongsToRole ( user_id = false,
user_role 
)

Check if user belongs to given role. Returns true if user belongs to user role.

Deprecated:
Parameters:
integer$user_id
integer$user_role
Returns:
boolean Returns true if user belongs to user role.
Author:
Jason Schoeman <titan@phpdevshell.org>
cacheClear ( unique_key = false)

Clear specific or all cache memory.

Parameters:
mixed$unique_key
cacheEmpty ( unique_key)

Checks if we have an empty cache container.

Parameters:
mixed$unique_key
Returns:
boolean
cacheRead ( unique_key)

Return exising cache result to required item.

Parameters:
mixed$unique_key
Returns:
mixed
cacheWrite ( unique_key,
cache_data,
compress = false,
timeout = false 
)

Writes new data to cache.

Parameters:
string$unique_key
mixed$cache_data
boolean$compress
int$timeout
connect ( )

Force database connection. FIX: Note this is used in core initiation to fix some dependent functions like mysql_real_escape_string requiring a DB connection. Only dbConnecter->query initiated the connection which was unfair to dependent functions.

Date:
20110622
Author:
Jason Schoeman
connectCacheServer ( )

Does the connection to the memcache server. Currently memcache is the primary supported engine.

connector ( connector = null)

Handle access to the alternate connector list

Give a class name, the connector will be instantiated if needed

Parameters:
string$connector,classname of the connector
Returns:
iPHPDS_dbConnector
countRows ( table_name,
column = false 
)

Simple method to count number of rows in a table.

Parameters:
string$table_name
string$column
Returns:
integer
Author:
Jason Schoeman <titan@phpdevshell.org>
deleteQuick ( from_table_name,
where_column_name,
is_equal_to_column_value,
return_column_value = false 
)

Delete data from the database with minimal effort.

Parameters:
string$from_table_name
string$where_column_name
string$is_equal_to_column_value
string$return_column_value
Returns:
string
Author:
Jason Schoeman <titan@phpdevshell.org>
deleteSettings ( settings_to_delete = false,
custom_prefix = false 
)

Delete all settings stored by a given plugins name, is used when uninstalling a plugin.

Example: deleteSettings(false, 'SimplePhonebook')

Parameters:
array$settings_to_deleteUse '*' to delete all settings for certain plugin.
string$custom_prefix
Returns:
boolean
Author:
Jason Schoeman <titan@phpdevshell.org>
doesRecordExist ( table_name,
search_column_names,
search_field_values,
column_name_for_exclusion = false,
exclude_field_value = false 
)

Determines whether the specified search string already exists in the specified field within the supplied table. Optional: Also looks at an id field (typically the primary key of a table) to make sure that the record you are working with is NOT included in the search. Usefull when modifying an existing record and you need first to check if another record with the same value doesn't already exist.

Parameters:
stringThe name of the database table.
mixedThe array names of the columns in which to look for the search strings, a single value can also be given.
mixedIn the same order as $search_column_name array, the search strings in array that should not be duplicated, a single value can also be given.
stringThe name of the primary key column name of the record you will be updating.
stringThe value of the primary key of the record you will be updating that should not be included in the search.
Returns:
boolean If TRUE is returned it means the record already exists, FALSE means the record doesn't exist.
Author:
Jason Schoeman <titan@phpdevshell.org>
endTransaction ( )

Commits database transactions.

Author:
Jason Schoeman <titan@phpdevshell.org>
getEssentialSettings ( )

Used to get all essential system settings from the database, preventing multiple queries.

Returns:
array Contains array with essential settings.
getGroups ( user_id = false,
return_array = false,
alias_only = false 
)

This function gets all group id's for given user ids, while returning a string divided by ',' character or an array with ids. To pull multiple user groups, provide a string for $user_ids like so : '2,5,10,19'.

Deprecated:
Parameters:
string$user_idLeave this field empty if you want skip if user is root.
boolean$return_array
string$alias_onlyIf you would like only items of a certain alias to be called.
Returns:
mixed If $return_array = false a comma delimited string will be returned, else an array.
Author:
Jason Schoeman <titan@phpdevshell.org>
getRoles ( user_id = false,
return_array = false 
)

This function gets all role id's for a given user id, while returning a string divided by ',' character or an array with ids. To pull multiple user roles, provide a string for $user_ids like so: '2,5,10,19'.

Deprecated:
Parameters:
string$user_id
boolean$return_array
Returns:
mixed If $return_array = false a comma delimited string will be returned, else an array.
Author:
Jason Schoeman <titan@phpdevshell.org>
getSettings ( settings_required = false,
custom_prefix = false 
)

Loads and returns required settings from database. Class will always use plugin name as prefix for settings if no custom prefix is provided.

Parameters:
array$settings_required
string$prefixThis allows you to use a prefix value of your choice to select a setting from another plugin, otherwise PHPDevShell will be used.
Returns:
array An array will be returned containing all the values requested.
Author:
Jason Schoeman <titan@phpdevshell.org>
groupExist ( group_id)

Simple check to see if a certain group exists.

Deprecated:
Parameters:
integer$group_id
Returns:
boolean
installedPlugins ( )

Writes array of all the installed plugins on the system.

Author:
Jason Schoeman <titan@phpdevshell.org>
invokeQuery ( query_name)

Locates the query class of the given name, loads it, intantiate it, send the query to the DB, and return the result

Date:
20100219
Version:
1.2
Date:
20100922 (1.2) (greg) now use invokeQueryWithArgs
Author:
greg
Parameters:
$query_namestring, the name of the query class (descendant of PHPDS_query)
Returns:
array (usually), the result data of the query
invokeQueryWith ( query_name,
params 
)

Locates the query class of the given name, loads it, intantiate it, send the query to the DB, and return the result

Date:
20100922 (1.0) (greg) added
Version:
1.0
Author:
greg
Parameters:
$query_namestring, the name of the query class (descendant of PHPDS_query)
$argsarray of parameters
Returns:
array (usually), the result data of the query
logMenuAccess ( )

Method logs menu access per user.

logThis ( )

This method logs error and success entries to the database.

Parameters:
integer$log_type
string$log_description
Author:
Jason Schoeman <titan@phpdevshell.org>
Version:
1.0.1 Changed mysql_escape_string() to mysql_real_escape_string() [see http://www.php.net/manual/en/function.mysql-escape-string.php ]
makeQuery ( query_name)

Locates the query class of the given name, loads it, intantiate it, and returns the query object

Date:
20100219 (greg) created
20110812 (v1.2) (greg) doesn't provide the query with the default connector anymore (let the query requests it at contruct time)
Version:
1.2
Author:
greg
Parameters:
$query_namestring, the name of the query class (descendant of PHPDS_query)
Returns:
PHPDS_query descendant, the query object
nameOfNewCopy ( table_name,
name_field,
orig_name 
)

This method is used to generate a new name value for a particular string in the database.

Usage Example : // This code generates a copy of the text "Some Value". The name_of_new_copy function // checks that it doesn't duplicate the name. $result = $db->nameOfNewCopy('PHPDS_table', 'some_field', 'Some Value');

// name_of_new_copy() returns 'Copy of Some Value', unless 'Copy of Some Value' already exists. If // it does, the function will return with 'Copy (x) of Some Value' where x is the next available // number that is not in use.

Parameters:
stringThe name of the table to search within.
stringThe fieldname to search withing.
stringThe original text to search for.
Author:
Don Schoeman <don@delphexonline.com>
newQuery ( query)

Compatibility Do direct sql query without models.

Date:
20110512
Parameters:
string
Version:
1.0
Author:
jason
Returns:
mixed
protect ( param)

Protect a single string from possible hacker (i.e. escape possible harmfull chars)

Actually deleguate the action to the connector

Date:
20100329
Version:
1.1
Author:
greg
Date:
20111018 (v1.1) (greg) $param can now be an array
Parameters:
$parammixed, the parameter to espace
Returns:
string, the escaped string/array
See also:
includes/PHPDS_db_connectorprotect()
protectArray ( array $  a,
quote = '' 
)

Protect a array of strings from possible hacker (i.e. escape possible harmfull chars) (this has been moved from PHPDS_query)

Version:
1.1
Date:
20111010 (v1.1) (greg) added "quote" parameter
Author:
greg
Parameters:
$aarray, the strings to protect
$quotestring, the quotes to add to each non-numerical scalar value
Returns:
array, the same string but safe
roleExist ( role_id)

Simple check to see if a certain role exists.

Deprecated:
Parameters:
integer$role_id
Returns:
boolean
selectQuick ( from_table_name,
select_column_name,
where_column_name,
is_equal_to_column_value 
)

Get a single result from database with minimal effort.

Parameters:
string$from_table_name
string$select_column_name
string$where_column_name
string$is_equal_to_column_value
Returns:
string
Author:
Jason Schoeman <titan@phpdevshell.org>
setGroupQuery ( query_request,
query_root_request = false 
)

Creates a query to extend a group query, it will return false if user is root so everything can get listed. This is meant to be used inside an existing group query.

Deprecated:
Parameters:
string$query_requestNormal query to be returned if user is not a root user.
string$query_root_requestIf you want a query to be processed for a root user seperately.
Returns:
mixed
setRoleQuery ( query_request,
query_root_request = false 
)

Creates a query to extend a role query, it will return false if user is root so everything can get listed. This is meant to be used inside an existing role query.

Deprecated:
Parameters:
string$query_requestNormal query to be returned if user is not a root user.
string$query_root_requestIf you want a query to be processed for a root user seperately.
Returns:
mixed
settingsPrefix ( custom_prefix = false)

Generates a prefix for plugin general settings.

Parameters:
string$custom_prefix
Returns:
string Complete string with prefix.
Author:
Jason Schoeman <titan@phpdevshell.org>
sqlQuery ( query)

Alias to newQuery

Parameters:
string$query
Returns:
mixed
startTransaction ( )

Set the starting point for a SQL transaction

You should call end_transaction(true) for the queries to actually occur

tableExist ( table)

Checks if a database table exists.

Parameters:
string$table
Returns:
boolean
writeSettings ( write_settings,
custom_prefix = '',
notes = array() 
)

Used to write general plugin settings to the database. Class will always use plugin name as prefix for settings if no custom prefix is provided. // Example: $db->writeSettings(array('setting_name'=>'value')[,'Example'][,array('setting_name'=>'note')]);

Parameters:
array$write_settingsThis array should contain settings to write.
string$custom_prefixIf you would like to have a custom prefix added to your settings.
array$notesFor adding notes about setting.
Returns:
boolean On success true will be returned.
Author:
Jason Schoeman <titan@phpdevshell.org>

Field Documentation

$connection
$connector [protected]
$connectors [protected]
$countQueries = -2
$dbName
$dbPassword
$dbUsername
$defaultQuery [protected]
$displaySqlInError = false
$essentialSettings
$logArray
$memcache
$pluginLogo
$pluginsInstalled
$result
$server

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