Moodle  2.2.1
http://www.collinsharper.com
pdo_moodle_database Class Reference
Inheritance diagram for pdo_moodle_database:
Collaboration diagram for pdo_moodle_database:

Public Member Functions

 __construct ($external=false)
 connect ($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null)
 get_name ()
 get_configuration_help ()
 get_configuration_hints ()
 get_server_info ()
 get_last_error ()
 change_database_structure ($sql)
 delete_records_select ($table, $select, array $params=null)
 execute ($sql, array $params=null)
 get_recordset_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 get_fieldset_sql ($sql, array $params=null)
 get_records_sql ($sql, array $params=null, $limitfrom=0, $limitnum=0)
 insert_record_raw ($table, $params, $returnid=true, $bulk=false, $customsequence=false)
 insert_record ($table, $dataobject, $returnid=true, $bulk=false)
 update_record_raw ($table, $params, $bulk=false)
 update_record ($table, $dataobject, $bulk=false)
 set_field_select ($table, $newfield, $newvalue, $select, array $params=null)
 sql_concat ()
 sql_concat_join ($separator="' '", $elements=array())
 import_record ($table, $dataobject)

Protected Member Functions

 get_dsn ()
 get_pdooptions ()
 configure_dbconnection ()
 get_dblibrary ()
 allowed_param_types ()
 debug_query ($sql, $params=null)
 create_recordset ($sth)
 begin_transaction ()
 commit_transaction ()
 rollback_transaction ()
 query_start ($sql, array $params=null, $type, $extrainfo=null)

Protected Attributes

 $pdb
 $lastError = null

Detailed Description

Experimental pdo database class

Definition at line 36 of file pdo_moodle_database.php.


Constructor & Destructor Documentation

__construct ( external = false)

Constructor - instantiates the database, specifying if it's external (connect to other systems) or no (Moodle DB) note this has effect to decide if prefix checks must be performed or no

Parameters:
booltrue means external database used

Reimplemented from moodle_database.

Definition at line 46 of file pdo_moodle_database.php.


Member Function Documentation

allowed_param_types ( ) [protected]

Returns supported query parameter types

Returns:
int bitmask

Reimplemented from moodle_database.

Definition at line 158 of file pdo_moodle_database.php.

begin_transaction ( ) [protected]

Driver specific start of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented from moodle_database.

Definition at line 544 of file pdo_moodle_database.php.

Here is the call graph for this function:

Do NOT use in code, to be used by database_manager only!

Parameters:
string$sqlquery
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 188 of file pdo_moodle_database.php.

Here is the call graph for this function:

commit_transaction ( ) [protected]

Driver specific commit of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented from moodle_database.

Definition at line 554 of file pdo_moodle_database.php.

Here is the call graph for this function:

configure_dbconnection ( ) [protected]

TODO: not needed preconfigure_dbconnection() stuff for PDO drivers?

Reimplemented in sqlite3_pdo_moodle_database.

Definition at line 99 of file pdo_moodle_database.php.

Here is the caller graph for this function:

connect ( dbhost,
dbuser,
dbpass,
dbname,
prefix,
array dboptions = null 
)

Connect to db Must be called before other methods.

Parameters:
string$dbhost
string$dbuser
string$dbpass
string$dbname
mixed$prefixstring means moodle db prefix, false used for external databases where prefix not used
array$dboptionsdriver specific options
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 61 of file pdo_moodle_database.php.

Here is the call graph for this function:

create_recordset ( sth) [protected]

Factory method that creates a recordset for return by a query. The generic pdo_moodle_recordset class should fit most cases, but pdo_moodle_database subclasses can override this method to return a subclass of pdo_moodle_recordset.

Parameters:
object$sthinstance of PDOStatement
Returns:
object instance of pdo_moodle_recordset

Definition at line 218 of file pdo_moodle_database.php.

Here is the caller graph for this function:

debug_query ( sql,
params = null 
) [protected]

Function to print/save/ignore debugging messages related to SQL queries.

Definition at line 173 of file pdo_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

delete_records_select ( table,
select,
array params = null 
)

Delete one or more records from a table which match a particular WHERE clause.

Parameters:
string$tableThe database table to be checked against.
string$selectA fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria).
array$paramsarray of sql parameters
Returns:
bool true.
Exceptions:
dml_exceptionif error

Reimplemented from moodle_database.

Definition at line 203 of file pdo_moodle_database.php.

Here is the call graph for this function:

execute ( sql,
array params = null 
)

Execute general sql query. Should be used only when no other method suitable. Do NOT use this to make changes in db structure, use database_manager::execute_sql() instead!

Parameters:
string$sqlquery
array$paramsquery parameters
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 229 of file pdo_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns localised database configuration help. Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 126 of file pdo_moodle_database.php.

Here is the call graph for this function:

Returns localised database description Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 135 of file pdo_moodle_database.php.

Here is the call graph for this function:

get_dblibrary ( ) [protected]

Returns general database library name Note: can be used before connect()

Returns:
string db type pdo, native

Reimplemented from moodle_database.

Definition at line 108 of file pdo_moodle_database.php.

get_dsn ( ) [abstract, protected]

Returns the driver-dependent DSN for PDO based on members stored by connect. Must be called after connect (or after $dbname, $dbhost, etc. members have been set).

Returns:
string driver-dependent DSN

Reimplemented in sqlite3_pdo_moodle_database.

Here is the caller graph for this function:

get_fieldset_sql ( sql,
array params = null 
)

Selects rows and return values of first column as array.

Parameters:
string$sqlThe SQL query
array$paramsarray of sql parameters
Returns:
array of values

Reimplemented from moodle_database.

Definition at line 289 of file pdo_moodle_database.php.

Here is the call graph for this function:

Returns last error reported by database engine.

Returns:
string error message

Reimplemented from moodle_database.

Definition at line 166 of file pdo_moodle_database.php.

get_name ( )

Returns localised database type name Note: can be used before connect()

Returns:
string

Reimplemented from moodle_database.

Definition at line 117 of file pdo_moodle_database.php.

Here is the call graph for this function:

get_pdooptions ( ) [protected]

Returns the driver-dependent connection attributes for PDO based on members stored by connect. Must be called after $dbname, $dbhost, etc. members have been set.

Returns:
array A key=>value array of PDO driver-specific connection options

Definition at line 95 of file pdo_moodle_database.php.

Here is the caller graph for this function:

get_records_sql ( sql,
array params = null,
limitfrom = 0,
limitnum = 0 
)

Get a number of records as an array of objects.

Return value as for

See also:
function get_records.
Parameters:
string$sqlthe SQL select query to execute. The first column of this SELECT statement must be a unique value (usually the 'id' field), as it will be used as the key of the returned array.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
array of objects, or empty array if no records were found, or false if an error occurred.

Reimplemented from moodle_database.

Definition at line 316 of file pdo_moodle_database.php.

Here is the call graph for this function:

get_recordset_sql ( sql,
array params = null,
limitfrom = 0,
limitnum = 0 
)

Get a number of records as an moodle_recordset. $sql must be a complete SQL query. Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records_sql - it leads to simpler code.

The return type is as for

See also:
function get_recordset.
Parameters:
string$sqlthe SQL select query to execute.
array$paramsarray of sql parameters
int$limitfromreturn a subset of records, starting at this point (optional, required if $limitnum is set).
int$limitnumreturn a subset comprising this many records (optional, required if $limitfrom is set).
Returns:
moodle_recordset instance

Reimplemented from moodle_database.

Definition at line 261 of file pdo_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns database server info array

Returns:
array

Reimplemented from moodle_database.

Definition at line 143 of file pdo_moodle_database.php.

import_record ( table,
dataobject 
)

Import a record into a table, id field is required. Basic safety checks only. Lobs are supported.

Parameters:
string$tablename of database table to be inserted into
mixed$dataobjectobject or array with fields in the record
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 583 of file pdo_moodle_database.php.

Here is the call graph for this function:

insert_record ( table,
dataobject,
returnid = true,
bulk = false 
)

Insert a record into a table and return the "id" field if required, Some conversions and safety checks are carried out. Lobs are supported. If the return ID isn't required, then this just reports success as true/false. $data is an object containing needed data

Parameters:
string$tableThe database table to be inserted into
object$dataA data object with values for one or more fields in the record
bool$returnidShould the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
bool$bulktrue means repeated inserts expected
Returns:
bool|int true or new id

Reimplemented from moodle_database.

Definition at line 390 of file pdo_moodle_database.php.

Here is the call graph for this function:

insert_record_raw ( table,
params,
returnid = true,
bulk = false,
customsequence = false 
)

Insert new record into database, as fast as possible, no safety checks, lobs not supported.

Parameters:
string$tablename
mixed$paramsdata record as object or array
bool$returnitreturn it of inserted record
bool$bulktrue means repeated inserts expected
bool$customsequencetrue if 'id' included in $params, disables $returnid
Returns:
bool|int true or new id

Reimplemented from moodle_database.

Definition at line 344 of file pdo_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:

query_start ( sql,
array params = null,
type,
extrainfo = null 
) [protected]

Called before each db query.

Overridden to ensure $this->lastErorr is reset each query

Parameters:
string$sql
arrayarray of parameters
int$typetype of query
mixed$extrainfodriver specific extra information
Returns:
void

Reimplemented from moodle_database.

Definition at line 609 of file pdo_moodle_database.php.

Here is the caller graph for this function:

rollback_transaction ( ) [protected]

Driver specific abort of real database transaction, this can not be used directly in code.

Returns:
void

Reimplemented from moodle_database.

Definition at line 565 of file pdo_moodle_database.php.

Here is the call graph for this function:

set_field_select ( table,
newfield,
newvalue,
select,
array params = null 
)

Set a single field in every table row where the select statement evaluates to true.

Parameters:
string$tableThe database table to be checked against.
string$newfieldthe field to set.
string$newvaluethe value to set the field to.
string$selectA fragment of SQL to be used in a where clause in the SQL call.
array$paramsarray of sql parameters
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 501 of file pdo_moodle_database.php.

Here is the call graph for this function:

Returns the proper SQL to do CONCAT between the elements passed Can take many parameters

This function accepts variable number of string parameters.

Returns:
string

Reimplemented from moodle_database.

Reimplemented in sqlite3_pdo_moodle_database.

Definition at line 536 of file pdo_moodle_database.php.

Here is the call graph for this function:

sql_concat_join ( separator = "' '",
elements = array() 
)

Returns the proper SQL to do CONCAT between the elements passed with a given separator

Parameters:
string$separator
array$elements
Returns:
string

Reimplemented from moodle_database.

Reimplemented in sqlite3_pdo_moodle_database.

Definition at line 540 of file pdo_moodle_database.php.

Here is the call graph for this function:

update_record ( table,
dataobject,
bulk = false 
)

Update a record in a table

$dataobject is an object containing needed data Relies on $dataobject having a variable "id" to specify the record to update

Parameters:
string$tableThe database table to be checked against.
object$dataobjectAn object with contents equal to fieldname=>fieldvalue. Must have an entry for 'id' to map to the table specified.
booltrue means repeated updates expected
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 472 of file pdo_moodle_database.php.

Here is the call graph for this function:

update_record_raw ( table,
params,
bulk = false 
)

Update record in database, as fast as possible, no safety checks, lobs not supported.

Parameters:
string$tablename
mixed$paramsdata record as object or array
booltrue means repeated updates expected
Returns:
bool success

Reimplemented from moodle_database.

Definition at line 435 of file pdo_moodle_database.php.

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

$lastError = null [protected]

Definition at line 39 of file pdo_moodle_database.php.

$pdb [protected]

Definition at line 38 of file pdo_moodle_database.php.


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