core/xpdo/xpdo.class.php
This is the main file to include in your scripts to use xPDO.
- Author
- Jason Coward
- Copyright
- Copyright (C) 2006-2012, Jason Coward
- License
- GNU Public License v2
- Package
- xpdo
Constants
\xPDO
A wrapper for PDO that powers an object-relational data model.
xPDO provides centralized data access via a simple object-oriented API, to a defined data structure. It provides the de facto methods for connecting to a data source, getting persistence metadata for any class extended from the {@link xPDOObject} class (core or custom), loading data source managers when needed to manage table structures, and retrieving instances (or rows) of any object in the model.
Through various extensions, you can also reverse and forward engineer classes and metadata maps for xPDO, have classes, models, and properties maintain their own containers (databases, tables, columns, etc.) or changes to them, and much more.
- Children
- \modX
Constants
Properties

boolean
$_cacheEnabled= 'false'
A global cache flag that can be used to enable/disable all xPDO caching.
All caching is disabled by default.falseDetails- Type
- boolean
- Access
- public

array
$_connections= 'array()'
array()Details- Type
- array

boolean
$_debug= 'false'
Indicates the debug state of this instance.
Default is false.falseDetails- Type
- boolean
- Access
- protected

string
$_escapeCharClose= ''''
Indicates the closing escape character used for a particular database engine.
''Details- Type
- string
- Access
- public

string
$_escapeCharOpen= ''''
Indicates the opening escape character used for a particular database engine.
''Details- Type
- string
- Access
- public

string
$_quoteChar= '"'"'
Represents the character used for quoting strings for a particular driver.
"'"Details- Type
- string

\xPDOCacheManager
$cacheManager= 'null'
nullDetails- Type
- \xPDOCacheManager

string
$cachePath= 'null'
nullDetails- Type
- string

array
$config= 'null'
nullDetails- Type
- array

\xPDOConnection
$connection= 'null'
nullDetails- Type
- \xPDOConnection

\xPDODriver
$driver= 'null'
nullDetails- Type
- \xPDODriver

int
$executedQueries= '0'
0Details- Type
- int

array
$instances= 'array()'
array()Details- Type
- array

integer
$logLevel= 'xPDO::LOG_LEVEL_FATAL'
xPDO::LOG_LEVEL_FATALDetails- Type
- integer

string
$logTarget= ''ECHO''
'ECHO'Details- Type
- string

\xPDOManager
$manager= 'null'
{@link xPDOManager} instance, loaded only if needed to manage datasource containers, data structures, etc.
nullDetails- Type
- \xPDOManager
- Access
- public

array
$map= 'array ()'
A map of data source meta data for all loaded classes.
array ()Details- Type
- array
- Access
- public

string
$package= ''''
A default package for specifying classes by name.
''Details- Type
- string
- Access
- public

array
$packages= 'array ()'
An array storing packages and package-specific information.
array ()Details- Type
- array
- Access
- public

\PDO
$pdo= 'null'
nullDetails- Type
- \PDO

int
$queryTime= '0'
0Details- Type
- int

array
$services= 'array ()'
array ()Details- Type
- array
Methods

__construct(
mixed $dsn, string $username
=
'', string $password
=
'', array | string $options
=
array(), array | null $driverOptions
=
null
)
:
\xPDOThe xPDO Constructor.
This method is used to create a new xPDO object with a connection to a specific database container.
| Name | Type | Description |
|---|---|---|
| $dsn | mixed | A valid DSN connection string. |
| $username | string | The database username with proper permissions. |
| $password | string | The password for the database user. |
| $options | array | string | An array of xPDO options. For compatibility with previous releases, this can also be a single string representing a prefix to be applied to all database container (i. e. table) names, to isolate multiple installations or conflicting table names that might need to coexist in a single database container. It is preferrable to include the table_prefix option in the array for future compatibility. |
| $driverOptions | array | null | Driver-specific PDO options. |
| Type | Description |
|---|---|
| \xPDO | A unique xPDO instance. |

_getFullTableName(
string $baseTableName, boolean $includeDb
=
false
)
:
stringAdds the table prefix, and optionally database name, to a given table.
| Name | Type | Description |
|---|---|---|
| $baseTableName | string | The table name as specified in the object model. |
| $includeDb | boolean | Qualify the table name with the database name. |
| Type | Description |
|---|---|
| string | The fully-qualified and quoted table name for the |

_getLogLevel(
integer $level
)
:
stringGets a logging level as a string representation.
| Name | Type | Description |
|---|---|---|
| $level | integer | The logging level to retrieve a string for. |
| Type | Description |
|---|---|
| string | The string representation of a valid logging level. |

_loadClass(
$class, $fqn, $included
=
false, $path
=
'', $transient
=
false
)
:
void| Name | Type | Description |
|---|---|---|
| $class | ||
| $fqn | ||
| $included | ||
| $path | ||
| $transient |

_log(
integer $level, string $msg, string $target
=
'', string $def
=
'', string $file
=
'', string $line
=
''
)
:
voidLog a message as appropriate for the level and target.
| Name | Type | Description |
|---|---|---|
| $level | integer | The level of the logged message. |
| $msg | string | The message to log. |
| $target | string | The logging target. |
| $def | string | The name of a defining structure (such as a class) to help identify the log event source. |
| $file | string | A filename in which the log event occured. |
| $line | string | A line number to help locate the source of the event within the indicated file. |

addConnection(
string $dsn, string $username
=
'', string $password
=
'', array $options
=
array(), null $driverOptions
=
null
)
:
booleanAdd an xPDOConnection instance to the xPDO connection pool.
| Name | Type | Description |
|---|---|---|
| $dsn | string | A PDO DSN representing the connection details. |
| $username | string | The username credentials for the connection. |
| $password | string | The password credentials for the connection. |
| $options | array | An array of options for the connection. |
| $driverOptions | null | An array of PDO driver options for the connection. |
| Type | Description |
|---|---|
| boolean | True if a valid connection was added. |

addDerivativeCriteria(
string $className, \xPDOCriteria $criteria
)
:
voidAdd criteria when requesting a derivative class row automatically.
This applies class_key filtering for single-table inheritance queries and may provide a convenient location for similar features in the future.
| Name | Type | Description |
|---|---|---|
| $className | string | A valid xPDOObject derivative table class. |
| $criteria | \xPDOCriteria | A valid xPDOCriteria instance. |

addPackage(
string $pkg
=
'', string $path
=
'', string | null $prefix
=
null
)
:
boolAdds a model package and base class path for including classes and/or maps from.
| Name | Type | Description |
|---|---|---|
| $pkg | string | A package name to use when looking up classes/maps in xPDO. |
| $path | string | The root path for looking up classes in this package. |
| $prefix | string | null | Provide a string to define a package-specific table_prefix. |
| Type | Description |
|---|---|
| bool |

call(
string $class, string $method, array $args
=
array(), boolean $transient
=
false
)
:
mixed | nullCall a static method from a valid package class with arguments.
Will always search for database-specific class files first.
| Name | Type | Description |
|---|---|---|
| $class | string | The name of a class to to get the static method from. |
| $method | string | The name of the method you want to call. |
| $args | array | An array of arguments for the method. |
| $transient | boolean | Indicates if the class has dbtype derivatives. Set to true if you want to use on classes not derived from xPDOObject. |
| Type | Description |
|---|---|
| mixed | null | The callback method's return value or null if no valid method is found. |

connect(
array $driverOptions
=
array (), $options
=
array()
)
:
booleanGet or create a PDO connection to a database specified in the configuration.
| Name | Type | Description |
|---|---|---|
| $driverOptions | array | An optional array of driver options to use when creating the connection. |
| $options |
| Type | Description |
|---|---|
| boolean | Returns true if the PDO connection was created successfully. |

escSplit(
string $char, string $str, string $escToken
=
'`', integer $limit
=
0
)
:
arraySplits a string on a specified character, ignoring escaped content.
| Name | Type | Description |
|---|---|---|
| $char | string | A character to split the tag content on. |
| $str | string | The string to operate on. |
| $escToken | string | A character used to surround escaped content; all content within a pair of these tokens will be ignored by the split operation. |
| $limit | integer | Limit the number of results. Default is 0 which is no limit. Note that setting the limit to 1 will only return the content up to the first instance of the split character and will discard the remainder of the string. |
| Type | Description |
|---|---|
| array | An array of results from the split operation, or an empty array. |
- Static

escape(
string $string
)
:
stringEscapes the provided string using the platform-specific escape character.
Different database engines escape string literals in SQL using different characters. For example, this is used to escape column names that might match a reserved string for that SQL interpreter. To write database agnostic queries with xPDO, it is highly recommend to escape any database or column names in any native SQL strings used.
| Name | Type | Description |
|---|---|---|
| $string | string | A string to escape using the platform-specific escape characters. |
| Type | Description |
|---|---|
| string | The string escaped with the platform-specific escape characters. |

exec(
$query
)
:
void| Name | Type | Description |
|---|---|---|
| $query |
- See
- \http://php.net/manual/en/function.pdo-exec.php

fromCache(
string | \xPDOCriteria $signature, string $class
=
'', array $options
=
array()
)
:
array | string | nullRetrieves a result array from the object cache.
| Name | Type | Description |
|---|---|---|
| $signature | string | \xPDOCriteria | A unique string or xPDOCriteria object that represents the query identifying the result set. |
| $class | string | An optional classname the result represents. |
| $options | array | Various cache options. |
| Type | Description |
|---|---|
| array | string | null | A PHP array or JSON object representing the result set, or null if no cache representation is found. |

fromJSON(
string $src, boolean $asArray
=
true
)
:
mixedConverts a JSON source string into an equivalent PHP representation.
| Name | Type | Description |
|---|---|---|
| $src | string | A JSON source string. |
| $asArray | boolean | Indicates if the result should treat objects as associative arrays; since all JSON associative arrays are objects, the default is true. Set to false to have JSON objects returned as PHP objects. |
| Type | Description |
|---|---|
| mixed | The PHP representation of the JSON source. |

getAggregates(
string $className
)
:
arrayGets a collection of aggregate foreign key relationship definitions.
| Name | Type | Description |
|---|---|---|
| $className | string | The fully-qualified name of the class. |
| Type | Description |
|---|---|
| array | An array of aggregate foreign key relationship definitions. |

getAncestry(
string $className, boolean $includeSelf
=
true
)
:
arrayRetrieves the complete ancestry for a class.
| Name | Type | Description |
|---|---|---|
| $className | string | className The name of the class. |
| $includeSelf | boolean | includeSelf Determines if the specified class should be included in the resulting array. |
| Type | Description |
|---|---|
| array | An array of string class names representing the class hierarchy, or an empty array if unsuccessful. |

getAttribute(
$attribute
)
:
void| Name | Type | Description |
|---|---|---|
| $attribute |
- See
- \http://php.net/manual/en/function.pdo-getattribute.php

getCacheManager(
string $class
=
'cache.xPDOCacheManager', array $options
=
array('path' => XPDO_CORE_PATH, 'ignorePkg' => true)
)
:
\xPDOCacheManagerGets an xPDOCacheManager instance.
This class is responsible for handling all types of caching operations for the xPDO core.
| Name | Type | Description |
|---|---|---|
| $class | string | Optional name of a derivative xPDOCacheManager class. |
| $options | array | An array of options for the cache manager instance; valid options include: - path = Optional root path for looking up the $class. - ignorePkg = If false and you do not specify a path, you can look up custom xPDOCacheManager derivatives in declared packages. |
| Type | Description |
|---|---|
| \xPDOCacheManager | The xPDOCacheManager for this xPDO instance. |

getCachePath(
)
:
stringGets the absolute path to the cache directory.
| Type | Description |
|---|---|
| string | The full cache directory path. |

getCollection(
string $className, object | array | string $criteria
=
null, mixed $cacheFlag
=
true
)
:
array | nullRetrieves a collection of xPDOObjects by the specified xPDOCriteria.
| Name | Type | Description |
|---|---|---|
| $className | string | Name of the class to search for instances of. |
| $criteria | object | array | string | An xPDOCriteria object or an array search expression. |
| $cacheFlag | mixed | If an integer value is provided, this specifies the time to live in the result set cache; if cacheFlag === false, caching is ignored for the collection and if cacheFlag === true, the objects will live in cache until flushed by another process. |
| Type | Description |
|---|---|
| array | null | An array of class instances retrieved. |

getCollectionGraph(
string $className, string | array $graph, mixed $criteria
=
null, boolean $cacheFlag
=
true
)
:
arrayRetrieves a collection of xPDOObject instances with related objects.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to return a collection of. |
| $graph | string | array | A related object graph in array or JSON format, e.g. array('relationAlias'=>array('subRelationAlias'=>array())) or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays are necessary in order for the relation to be recognized. |
| $criteria | mixed | A valid xPDOCriteria instance or condition string. |
| $cacheFlag | boolean | Indicates if the result set should be cached. |
| Type | Description |
|---|---|
| array | An array of instances matching the criteria with related objects from the graph hydrated. An empty array is returned when no matches are found. |
- Used_by
- \modX::getObjectGraph()
- Used_by
- \xPDO::getObjectGraph()
- Uses
- \xPDOQuery::bindGraph()

getComposites(
string $className
)
:
arrayGets a collection of composite foreign key relationship definitions.
| Name | Type | Description |
|---|---|---|
| $className | string | The fully-qualified name of the class. |
| Type | Description |
|---|---|
| array | An array of composite foreign key relationship definitions. |

getConnection(
array $options
=
array()
)
:
\xPDOConnection | nullGet an xPDOConnection from the xPDO connection pool.
| Name | Type | Description |
|---|---|---|
| $options | array | An array of options for getting the connection. |
| Type | Description |
|---|---|
| \xPDOConnection | null | An xPDOConnection instance or null if no connection could be retrieved. |

getCount(
string $className, mixed $criteria
=
null
)
:
integerRetrieves a count of xPDOObjects by the specified xPDOCriteria.
| Name | Type | Description |
|---|---|---|
| $className | string | Class of xPDOObject to count instances of. |
| $criteria | mixed | Any valid xPDOCriteria object or expression. |
| Type | Description |
|---|---|
| integer | The number of instances found by the criteria. |

getCriteria(
string $className, string $type
=
null, boolean | integer $cacheFlag
=
true
)
:
\xPDOCriteriaConvert any valid criteria into an xPDOQuery instance.
| Name | Type | Description |
|---|---|---|
| $className | string | The class to get predefined criteria for. |
| $type | string | The type of criteria to get (you can define any type you want, but 'object' and 'collection' are the typical criteria for retrieving single and multiple instances of an object). |
| $cacheFlag | boolean | integer | Indicates if the result is cached and optionally for how many seconds. |
| Type | Description |
|---|---|
| \xPDOCriteria | A criteria object or null if not found. |
- Todo
- Get criteria pre-defined in an {@link xPDOObject} class metadata definition by name.
- Todo
- Define callback functions as an alternative to retreiving criteria sql and/or bindings from the metadata.

getCriteriaType(
mixed $criteria
)
:
string | nullValidate and return the type of a specified criteria variable.
| Name | Type | Description |
|---|---|---|
| $criteria | mixed | An xPDOCriteria instance or any valid criteria variable. |
| Type | Description |
|---|---|
| string | null | The type of valid criteria passed, or null if the criteria is not valid. |

getDebug(
)
:
booleanReturns the debug state for the xPDO instance.
| Type | Description |
|---|---|
| boolean | The current debug state for the instance, true for on, false for off. |

getDebugBacktrace(
)
:
arrayReturns an abbreviated backtrace of debugging information.
This function returns just the fields returned via xPDOObject::toArray() on xPDOObject instances, and simply the classname for other objects, to reduce the amount of unnecessary information returned.
| Type | Description |
|---|---|
| array | The abbreviated backtrace. |

getDescendants(
string $className
)
:
arrayGets a list of derivative classes for the specified xPDOObject instance.
NOTE: Will not work with xPDOObject/xPDOSimpleObject.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to retrieve derivatives for. |
| Type | Description |
|---|---|
| array | An array of derivative classes or an empty array. |

getDriver(
)
:
\xPDODriver | nullGets the driver class for this xPDO connection.
The driver class provides baseline data and operations for a specific database driver.
| Type | Description |
|---|---|
| \xPDODriver | null | An xPDODriver instance for the xPDO connection, or null if a driver class can not be instantiated. |

getFKDefinition(
string $parentClass, string $alias
)
:
arrayGets an aggregate or composite relation definition from a class.
| Name | Type | Description |
|---|---|---|
| $parentClass | string | The class from which the relation is defined. |
| $alias | string | The alias identifying the related class. |
| Type | Description |
|---|---|
| array | The aggregate or composite definition details in an array or null if no definition is found. |

getFieldAliases(
string $className
)
:
arrayGets a collection of field aliases for an object by class name.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup field aliases for. |
| Type | Description |
|---|---|
| array | An array of field aliases with aliases as keys and actual field names as values. |

getFieldMeta(
string $className, boolean $includeExtended
=
false
)
:
arrayGets a list of field (or column) definitions for an object by class name.
These definitions are used by the objects themselves to build their own meta data based on class inheritance.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup fields meta data for. |
| $includeExtended | boolean | If true, include meta from all derivative classes in loaded packages. |
| Type | Description |
|---|---|
| array | An array featuring field names as the array keys, and arrays of metadata information as the array values; empty array is returned if unsuccessful. |

getFields(
string $className
)
:
arrayGets a list of fields (or columns) for an object by class name.
This includes default values for each field and is used by the objects themselves to build their initial attributes based on class inheritence.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup fields for. |
| Type | Description |
|---|---|
| array | An array featuring field names as the array keys, and default field values as the array values; empty array is returned if unsuccessful. |

getGraph(
string $className, int $depth
=
3, array $parents
=
array(), array $visited
=
array()
)
:
arrayGet a complete relation graph for an xPDOObject class.
| Name | Type | Description |
|---|---|---|
| $className | string | A fully-qualified xPDOObject class name. |
| $depth | int | The depth to retrieve relations for the graph, defaults to 3. |
| $parents | array | &$parents An array of parent classes to avoid traversing circular dependencies. |
| $visited | array | &$visited An array of already visited classes to avoid traversing circular dependencies. |
| Type | Description |
|---|---|
| array | An xPDOObject relation graph, or an empty array if no graph can be constructed. |

getIndexMeta(
string $className
)
:
arrayGet indices defined for a table class.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup indices for. |
| Type | Description |
|---|---|
| array | An array of indices and their details for the specified class. |

getInherit(
\$className $className
)
:
stringIndicates the inheritance model for the xPDOObject class specified.
| Name | Type | Description |
|---|---|---|
| $className | \$className | The class to determine the table inherit type from. |
| Type | Description |
|---|---|
| string | single, multiple, or none |

getInstance(
string | int | null $id
=
null, array | null $config
=
null, bool $forceNew
=
false
)
:
\xPDOCreate, retrieve, or update specific xPDO instances.
| Name | Type | Description |
|---|---|---|
| $id | string | int | null | An optional identifier for the instance. If not set a uniqid will be generated and used as the key for the instance. |
| $config | array | null | An optional array of config data for the instance. |
| $forceNew | bool | If true a new instance will be created even if an instance with the provided $id already exists in xPDO::$instances. |
| Type | Description |
|---|---|
| \xPDO | An instance of xPDO. |
- Static

getIterator(
string $className, mixed $criteria
=
null, bool $cacheFlag
=
true
)
:
\xPDOIteratorRetrieves an iterable representation of a collection of xPDOObjects.
| Name | Type | Description |
|---|---|---|
| $className | string | Name of the class to search for instances of. |
| $criteria | mixed | An xPDOCriteria object or representation. |
| $cacheFlag | bool | If an integer value is provided, this specifies the time to live in the result set cache; if cacheFlag === false, caching is ignored for the collection and if cacheFlag === true, the objects will live in cache until flushed by another process. |
| Type | Description |
|---|---|
| \xPDOIterator | An iterable representation of a collection. |

getManager(
)
:
\xPDOManager | nullGets the manager class for this xPDO connection.
The manager class can perform operations such as creating or altering table structures, creating data containers, generating custom persistence classes, and other advanced operations that do not need to be loaded frequently.
| Type | Description |
|---|---|
| \xPDOManager | null | An xPDOManager instance for the xPDO connection, or null if a manager class can not be instantiated. |

getMicroTime(
)
:
floatConvert current microtime() result into seconds.
| Type | Description |
|---|---|
| float |

getModelVersion(
string $className
)
:
stringGets the version string of the schema the specified class was generated from.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to get the model version from. |
| Type | Description |
|---|---|
| string | The version string for the schema model the class was generated from. |

getObject(
string $className, mixed $criteria
=
null, mixed $cacheFlag
=
true
)
:
object | nullRetrieves a single object instance by the specified criteria.
The criteria can be a primary key value, and array of primary key values (for multiple primary key objects) or an {@link xPDOCriteria} object. If no $criteria parameter is specified, no class is found, or an object cannot be located by the supplied criteria, null is returned.
| Name | Type | Description |
|---|---|---|
| $className | string | Name of the class to get an instance of. |
| $criteria | mixed | Primary key of the record or a xPDOCriteria object. |
| $cacheFlag | mixed | If an integer value is provided, this specifies the time to live in the object cache; if cacheFlag === false, caching is ignored for the object and if cacheFlag === true, the object will live in cache indefinitely. |
| Type | Description |
|---|---|
| object | null | An instance of the class, or null if it could not be instantiated. |
- Uses
- \xPDOObject::load()

getObjectGraph(
string $className, string | array $graph, mixed $criteria
=
null, boolean | integer $cacheFlag
=
true
)
:
objectRetrieves an xPDOObject instance with specified related objects.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to return an instance of. |
| $graph | string | array | A related object graph in array or JSON format, e.g. array('relationAlias'=>array('subRelationAlias'=>array())) or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays are necessary in order for the relation to be recognized. |
| $criteria | mixed | A valid xPDOCriteria instance or expression. |
| $cacheFlag | boolean | integer | Indicates if the result set should be cached, and optionally for how many seconds. |
| Type | Description |
|---|---|
| object | The object instance with related objects from the graph hydrated, or null if no instance can be located by the criteria. |

getObjectLoader(
string $className, string $method
)
:
\callableFinds the class responsible for loading instances of the specified class.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to find a loader for. |
| $method | string | Indicates the specific loader method to use, loadCollection or loadObject (or other public static methods). |
| Type | Description |
|---|---|
| \callable | A callable loader function. |
- Deprecated
- Use call() instead.

getOption(
string $key, array $options
=
null, mixed $default
=
null, $skipEmpty
=
false
)
:
mixedGet an xPDO configuration option value by key.
| Name | Type | Description |
|---|---|---|
| $key | string | The option key. |
| $options | array | A set of options to override those from xPDO. |
| $default | mixed | An optional default value to return if no value is found. |
| $skipEmpty |
| Type | Description |
|---|---|
| mixed | The configuration option value. |

getPDOType(
mixed $value
)
:
int | nullGet the appropriate PDO::PARAM_ type constant from a PHP value.
| Name | Type | Description |
|---|---|---|
| $value | mixed | Any PHP scalar or null value |
| Type | Description |
|---|---|
| int | null |

getPK(
string $className
)
:
mixedGets the primary key field(s) for a class.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup the primary key for. |
| Type | Description |
|---|---|
| mixed | The name of the field representing a class instance primary key, an array of key names for compound primary keys, or null if no primary key is found or defined for the class. |

getPKType(
string $className, $pk
=
false
)
:
stringGets the type of primary key field for a class.
| Name | Type | Description |
|---|---|---|
| $className | string | className The name of the class to lookup the primary key type for. |
| $pk |
| Type | Description |
|---|---|
| string | The type of the field representing a class instance primary key, or null if no primary key is found or defined for the class. |
- Todo
- Refactor method to return array of types rather than compound!

getPackage(
string $className
)
:
stringGets the package name from a specified class name.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup the package for. |
| Type | Description |
|---|---|
| string | The package the class belongs to. |

getSelectColumns(
string $className, string $tableAlias
=
'', string $columnPrefix
=
'', array $columns
=
array (), boolean $exclude
=
false
)
:
stringGets select columns from a specific class for building a query.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to build the column list from. |
| $tableAlias | string | An optional alias for the class table, to be used in complex queries with multiple tables. |
| $columnPrefix | string | An optional string with which to prefix the columns returned, to avoid name collisions in return columns. |
| $columns | array | An optional array of columns to include. |
| $exclude | boolean | If true, will exclude columns in the previous parameter, instead of including them. |
| Type | Description |
|---|---|
| string | A valid SQL string of column names for a SELECT statement. |

getService(
string $name, string $class
=
'', string $path
=
'', array $params
=
array ()
)
:
object | nullLoad and return a named service class instance.
| Name | Type | Description |
|---|---|---|
| $name | string | The variable name of the instance. |
| $class | string | The service class name. |
| $path | string | An optional root path to search for the class. |
| $params | array | An array of optional params to pass to the service class constructor. |
| Type | Description |
|---|---|
| object | null | A reference to the service class instance or null if it could not be loaded. |

getTableClass(
string $className
)
:
null | stringGet the class which defines the table for a specified className.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of a class to determine the table class from. |
| Type | Description |
|---|---|
| null | string | The name of a class defining the table for the specified className; null if not found. |

getTableMeta(
string $className
)
:
stringGets the actual run-time table metadata from a specified class name.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup a table name for. |
| Type | Description |
|---|---|
| string | The table meta data for the class, or null if unsuccessful. |

getTableName(
string $className, boolean $includeDb
=
false
)
:
stringGets the actual run-time table name from a specified class name.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup a table name for. |
| $includeDb | boolean | Qualify the table name with the database name. |
| Type | Description |
|---|---|
| string | The table name for the class, or null if unsuccessful. |

getValidationRules(
string $className
)
:
arrayGets a set of validation rules defined for an object by class name.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to lookup validation rules for. |
| Type | Description |
|---|---|
| array | An array featuring field names as the array keys, and arrays of validation rule information as the array values; empty array is returned if unsuccessful. |

getValue(
\PDOStatement $stmt, null | integer $column
=
null
)
:
mixedExecute a PDOStatement and get a single column value from the first row of the result set.
| Name | Type | Description |
|---|---|---|
| $stmt | \PDOStatement | A prepared PDOStatement object ready to be executed. |
| $column | null | integer | 0-indexed number of the column you wish to retrieve from the row. If null or no value is supplied, it fetches the first column. |
| Type | Description |
|---|---|
| mixed | The value of the specified column from the first row of the result set, or null. |

initConfig(
string | array $data
)
:
arrayInitialize an xPDO config array.
| Name | Type | Description |
|---|---|---|
| $data | string | array | The config input source. Currently accepts a PHP array, or a PHP string representing xPDO::OPT_TABLE_PREFIX (deprecated). |
| Type | Description |
|---|---|
| array | An array of xPDO config data. |

literal(
string $string
)
:
stringUse to insert a literal string into a SQL query without escaping or quoting.
| Name | Type | Description |
|---|---|---|
| $string | string | A string to return as a literal, unescaped and unquoted. |
| Type | Description |
|---|---|
| string | The string with any escape or quote characters trimmed. |

loadClass(
string $fqn, $path
=
'', $ignorePkg
=
false, $transient
=
false
)
:
string | booleanLoad a class by fully qualified name.
The $fqn should in the format:
dir_a.dir_b.dir_c.classname
which will translate to:
XPDO_CORE_PATH/om/dir_a/dir_b/dir_c/dbtype/classname.class.php
| Name | Type | Description |
|---|---|---|
| $fqn | string | The fully-qualified name of the class to load. |
| $path | ||
| $ignorePkg | ||
| $transient |
| Type | Description |
|---|---|
| string | boolean | The actual classname if successful, or false if not. |

log(
integer $level, string $msg, string $target
=
'', string $def
=
'', string $file
=
'', string $line
=
''
)
:
voidLog a message with details about where and when an event occurs.
| Name | Type | Description |
|---|---|---|
| $level | integer | The level of the logged message. |
| $msg | string | The message to log. |
| $target | string | The logging target. |
| $def | string | The name of a defining structure (such as a class) to help identify the message source. |
| $file | string | A filename in which the log event occured. |
| $line | string | A line number to help locate the source of the event within the indicated file. |

newObject(
string $className, array $fields
=
array ()
)
:
object | nullCreates a new instance of a specified class.
All new objects created with this method are transient until {@link xPDOObject::save()} is called the first time and is reflected by the {@link xPDOObject::$_new} property.
| Name | Type | Description |
|---|---|---|
| $className | string | Name of the class to get a new instance of. |
| $fields | array | An associated array of field names/values to populate the object with. |
| Type | Description |
|---|---|
| object | null | A new instance of the specified class, or null if a new object could not be instantiated. |

newQuery(
string $class, mixed $criteria
=
null, boolean | integer $cacheFlag
=
true
)
:
\xPDOQueryCreates an new xPDOQuery for a specified xPDOObject class.
| Name | Type | Description |
|---|---|---|
| $class | string | The class to create the xPDOQuery for. |
| $criteria | mixed | Any valid xPDO criteria expression. |
| $cacheFlag | boolean | integer | Indicates if the result should be cached and optionally for how many seconds (if passed an integer greater than 0). |
| Type | Description |
|---|---|
| \xPDOQuery | The resulting xPDOQuery instance or false if unsuccessful. |

parseBindings(
string $sql, array $bindings
)
:
stringParses parameter bindings in SQL prepared statements.
| Name | Type | Description |
|---|---|---|
| $sql | string | A SQL prepared statement to parse bindings in. |
| $bindings | array | An array of parameter bindings to use for the replacements. |
| Type | Description |
|---|---|
| string | The SQL with the binding placeholders replaced. |

parseDSN(
string $string
)
:
arrayParses a DSN and returns an array of the connection details.
| Name | Type | Description |
|---|---|---|
| $string | string | The DSN to parse. |
| Type | Description |
|---|---|
| array | An array of connection details from the DSN. |
- Static
- Todo
- Have this method handle all methods of DSN specification as handled by latest native PDO implementation.

prepare(
$statement, $driver_options
=
array ()
)
:
void| Name | Type | Description |
|---|---|---|
| $statement | ||
| $driver_options |
- See
- \http://php.net/manual/en/function.pdo-prepare.php

query(
$query
)
:
void| Name | Type | Description |
|---|---|---|
| $query |
- See
- \http://php.net/manual/en/function.pdo-query.php

quote(
$string, $parameter_type
=
PDO::PARAM_STR
)
:
void| Name | Type | Description |
|---|---|---|
| $string | ||
| $parameter_type |
- See
- \http://php.net/manual/en/function.pdo-quote.php

removeCollection(
string $className, mixed $criteria
)
:
boolean | integerRemove a collection of instances by the supplied className and criteria.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to remove a collection of. |
| $criteria | mixed | Valid xPDO criteria for selecting a collection. |
| Type | Description |
|---|---|
| boolean | integer | False if the remove encounters an error, otherwise an integer value representing the number of rows that were removed. |

removeObject(
string $className, mixed $criteria
)
:
booleanRemove an instance of the specified className by a supplied criteria.
| Name | Type | Description |
|---|---|---|
| $className | string | The name of the class to remove an instance of. |
| $criteria | mixed | Valid xPDO criteria for selecting an instance. |
| Type | Description |
|---|---|
| boolean | True if the instance is successfully removed. |

setAttribute(
$attribute, $value
)
:
void| Name | Type | Description |
|---|---|---|
| $attribute | ||
| $value |
- See
- \http://php.net/manual/en/function.pdo-setattribute.php

setDebug(
boolean | integer $v
=
true
)
:
voidSets the debug state for the xPDO instance.
| Name | Type | Description |
|---|---|---|
| $v | boolean | integer | The debug status, true for on, false for off, or a valid error_reporting level for PHP. |

setLogLevel(
integer $level
=
xPDO::LOG_LEVEL_FATAL
)
:
integerSets the logging level state for the xPDO instance.
| Name | Type | Description |
|---|---|---|
| $level | integer | The logging level to switch to. |
| Type | Description |
|---|---|
| integer | The previous log level. |

setLogTarget(
string $target
=
'ECHO'
)
:
mixedSets the log target for xPDO::_log() calls.
Valid target values include:
- 'ECHO': Returns output to the STDOUT.
- 'HTML': Returns output to the STDOUT with HTML formatting.
- 'FILE': Sends output to a log file.
- An array with at least one element with key 'target' matching one of the valid log targets listed above. For 'target' => 'FILE' you can specify a second element with key 'options' with another associative array with one or both of the elements 'filename' and 'filepath'
| Name | Type | Description |
|---|---|---|
| $target | string | An identifier indicating the target of the logging. |
| Type | Description |
|---|---|
| mixed | The previous log target. |

setOption(
string $key, mixed $value
)
:
voidSets an xPDO configuration option value.
| Name | Type | Description |
|---|---|---|
| $key | string | The option key. |
| $value | mixed | A value to set for the given option key. |

setPackage(
string $pkg
=
'', string $path
=
'', string | null $prefix
=
null
)
:
boolSets a specific model package to use when looking up classes.
This package is of the form package.subpackage.subsubpackage and will be added to the beginning of every xPDOObject class that is referenced in xPDO methods such as {@link xPDO::loadClass()}, {@link xPDO::getObject()}, {@link xPDO::getCollection()}, {@link xPDOObject::getOne()}, {@link xPDOObject::addOne()}, etc.
| Name | Type | Description |
|---|---|---|
| $pkg | string | A package name to use when looking up classes in xPDO. |
| $path | string | The root path for looking up classes in this package. |
| $prefix | string | null | Provide a string to define a package-specific table_prefix. |
| Type | Description |
|---|---|
| bool |

setPackageMeta(
string $pkg, string $path
=
''
)
:
boolAdds metadata information about a package and loads the xPDO::$classMap.
| Name | Type | Description |
|---|---|---|
| $pkg | string | A package name to use when looking up classes/maps in xPDO. |
| $path | string | The root path for looking up classes in this package. |
| Type | Description |
|---|---|
| bool |

toCache(
string | \xPDOCriteria $signature, object $object, integer $lifetime
=
0, array $options
=
array()
)
:
booleanPlaces a result set in the object cache.
| Name | Type | Description |
|---|---|---|
| $signature | string | \xPDOCriteria | A unique string or xPDOCriteria object representing the object. |
| $object | object | An object to place a representation of in the cache. |
| $lifetime | integer | An optional number of seconds the cached result will remain valid, with 0 meaning it will remain valid until replaced or removed. |
| $options | array | Various cache options. |
| Type | Description |
|---|---|
| boolean | Indicates if the object was successfully cached. |

toJSON(
array $array
)
:
stringConverts a PHP array into a JSON encoded string.
| Name | Type | Description |
|---|---|---|
| $array | array | The PHP array to convert. |
| Type | Description |
|---|---|
| string | The JSON representation of the source array. |

updateCollection(
string $className, array $set, mixed $criteria
=
null
)
:
bool | intUpdate field values across a collection of xPDOObjects.
| Name | Type | Description |
|---|---|---|
| $className | string | Name of the class to update fields of. |
| $set | array | An associative array of field/value pairs representing the updates to make. |
| $criteria | mixed | An xPDOCriteria object or representation. |
| Type | Description |
|---|---|
| bool | int | The number of instances affected by the update or false on failure. |
\xPDOConnection
Represents a unique PDO connection managed by xPDO.
Properties

boolean
$_mutable= 'true'
trueDetails- Type
- boolean

array
$config= 'array()'
array()Details- Type
- array

\PDO
$pdo= 'null'
nullDetails- Type
- \PDO
Methods

__construct(
\xPDO $xpdo, string $dsn, string $username
=
'', string $password
=
'', array $options
=
array(), array $driverOptions
=
array()
)
:
voidConstruct a new xPDOConnection instance.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | A reference to a valid xPDO instance to attach to. |
| $dsn | string | A string representing the DSN connection string. |
| $username | string | The database username credentials. |
| $password | string | The database password credentials. |
| $options | array | An array of xPDO options for the connection. |
| $driverOptions | array | An array of PDO driver options for the connection. |

connect(
array $driverOptions
=
array()
)
:
boolActually make a connection for this instance via PDO.
| Name | Type | Description |
|---|---|---|
| $driverOptions | array | An array of PDO driver options for the connection. |
| Type | Description |
|---|---|
| bool | True if a successful connection is made. |

getOption(
$key, $options
=
null, $default
=
null
)
:
void| Name | Type | Description |
|---|---|---|
| $key | ||
| $options | ||
| $default |
\xPDOCriteria
Encapsulates a SQL query into a PDOStatement with a set of bindings.
- Children
- \xPDOQuery
Properties
Methods

__construct(
\xPDO $xpdo, string $sql
=
'', array $bindings
=
array (), boolean | integer $cacheFlag
=
false
)
:
\xPDOCriteriaThe constructor for a new xPDOCriteria instance.
The constructor optionally prepares provided SQL and/or parameter bindings. Setting the bindings via the constructor or with the {@link xPDOCriteria::bind()} function allows you to make use of the data object caching layer.
The statement will not be prepared immediately if the cacheFlag value is true or a positive integer, in order to allow the result to be found in the cache before being queried from an actual database connection.
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo An xPDO instance that will control this criteria. |
| $sql | string | The SQL statement. |
| $bindings | array | Bindings to bind to the criteria. |
| $cacheFlag | boolean | integer | Indicates if the result set from the criteria is to be cached (true|false) or optionally a TTL in seconds. |
| Type | Description |
|---|---|
| \xPDOCriteria |

bind(
array $bindings
=
array (), boolean $byValue
=
true, boolean | integer $cacheFlag
=
false
)
:
voidBinds an array of key/value pairs to the xPDOCriteria prepared statement.
Use this method to bind parameters in a way that makes it possible to cache results of previous executions of the criteria or compare the criteria to other individual or collections of criteria.
| Name | Type | Description |
|---|---|---|
| $bindings | array | Bindings to merge with any existing bindings defined for this xPDOCriteria instance. Bindings can be simple associative array of key-value pairs or the value for each key can contain elements titled value, type, and length corresponding to the appropriate parameters in the PDOStatement::bindValue() and PDOStatement::bindParam() functions. |
| $byValue | boolean | Determines if the $bindings are to be bound as parameters (by variable reference, the default behavior) or by direct value (if true). |
| $cacheFlag | boolean | integer | The cacheFlag indicates the cache state of the xPDOCriteria object and can be absolutely off (false), absolutely on (true), or an integer indicating the number of seconds the result will live in the cache. |

equals(
object $obj
)
:
booleanCompares to see if two xPDOCriteria instances are the same.
| Name | Type | Description |
|---|---|---|
| $obj | object | A xPDOCriteria object to compare to this one. |
| Type | Description |
|---|---|
| boolean | true if they are both equal is SQL and bindings, otherwise false. |

prepare(
array $bindings
=
array (), boolean $byValue
=
true, boolean | integer $cacheFlag
=
null
)
:
\PDOStatementPrepares the sql and bindings of this instance into a PDOStatement.
The {@link xPDOCriteria::$sql} attribute must be set in order to prepare the statement. You can also pass bindings directly to this function and they will be run through {@link xPDOCriteria::bind()} if the statement is successfully prepared.
If the {@link xPDOCriteria::$stmt} already exists, it is simply returned.
| Name | Type | Description |
|---|---|---|
| $bindings | array | Bindings to merge with any existing bindings defined for this xPDOCriteria instance. Bindings can be simple associative array of key-value pairs or the value for each key can contain elements titled value, type, and length corresponding to the appropriate parameters in the PDOStatement::bindValue() and PDOStatement::bindParam() functions. |
| $byValue | boolean | Determines if the $bindings are to be bound as parameters (by variable reference, the default behavior) or by direct value (if true). |
| $cacheFlag | boolean | integer | The cacheFlag indicates the cache state of the xPDOCriteria object and can be absolutely off (false), absolutely on (true), or an integer indicating the number of seconds the result will live in the cache. |
| Type | Description |
|---|---|
| \PDOStatement | The prepared statement, ready to execute. |
\xPDOException
\xPDOIterator
An iteratable representation of an xPDOObject result set.
Use an xPDOIterator to loop over large result sets and work with one instance at a time. This greatly reduces memory usage over loading the entire collection of objects into memory at one time. It is also slightly faster.
- Parent(s)
- ?\Iterator
Properties
Methods

__construct(
\xPDO $xpdo, array $options
=
array()
)
:
\xPDOIteratorConstruct a new xPDOIterator instance (do not call directly).
| Name | Type | Description |
|---|---|---|
| $xpdo | \xPDO | &$xpdo A reference to a valid xPDO instance. |
| $options | array | An array of options for the iterator. |
| Type | Description |
|---|---|
| \xPDOIterator | An xPDOIterator instance. |

fetch(
)
:
voidFetch the next row from the result set and set it as current.
Calls the _loadInstance() method for the specified class, so it properly inherits behavior from xPDOObject derivatives.