1. Overview
      1. What It Is
      2. Why I Would Want to Use It
      3. Known Issues
    2. Getting Started
      1. Fundamentals
        1. Design Patterns
        2. xPDO, the Class
          1. As Object and Relational Mapper
          2. As PDO Wrapper
          3. As Service Layer
          4. The xPDO Constructor
            1. Hydrating Fields
      2. Introduction to the xPDO Object Model
        1. Understanding xPDOCriteria and xPDOQuery
      3. Creating a Model With xPDO
        1. Defining a Schema
          1. Defining Relationships
          2. Defining the Database and Tables
            1. Upgrading Models to Schema Version 1.1
          3. More Examples of xPDO XML Schema Files
          4. Validation Rules in your Schema
        2. Generating the Model Code
          1. Domain Classes
          2. O-R Maps
          3. Table Classes
      4. Using Your xPDO Model
        1. Creating Objects
        2. Database Connections and xPDO
        3. Loading Packages
        4. Removing Objects
          1. removeCollection
        5. Retrieving Objects
          1. getCollectionGraph
        6. Setting Object Fields
        7. Working with Related Objects
    3. Extending Your xPDO Model
      1. Overriding Derived Behavior
        1. Using Custom Object Loaders
      2. Working With Transient Object Classes
    4. Advanced Features
      1. Caching
        1. Caching Tutorial - Basic Snippets
        2. Caching Tutorial - Lifetimes
      2. Object Validation
        1. xPDOForeignKeyConstraint
        2. xPDOMaxLengthValidationRule
        3. xPDOMaxValueValidationRule
        4. xPDOMinLengthValidationRule
        5. xPDOMinValueValidationRule
        6. xPDOObjectExistsValidationRule
    5. xPDO Development
      1. Testing
      2. Building
      3. Documentation and Tutorials
    6. Class Reference
      1. xPDO
        1. xPDO.addPackage
        2. xPDO.beginTransaction
        3. xPDO.commit
        4. xPDO.connect
        5. xPDO.fromJSON
        6. xPDO.getCollection
        7. xPDO.getCollectionGraph
        8. xPDO.getCount
        9. xPDO.getDebug
        10. xPDO.getFields
        11. xPDO.getIterator
        12. xPDO.getManager
        13. xPDO.getObject
        14. xPDO.getObjectGraph
        15. xPDO.getOption
        16. xPDO.getTableName
        17. xPDO.loadClass
        18. xPDO.log
        19. xPDO.newObject
        20. xPDO.newQuery
        21. xPDO.query
        22. xPDO.setDebug
        23. xPDO.setLogLevel
        24. xPDO.setLogTarget
        25. xPDO.setOption
        26. xPDO.toJSON
      2. xPDOCacheManager
        1. xPDOCacheManager.copyFile
        2. xPDOCacheManager.copyTree
        3. xPDOCacheManager.delete
        4. xPDOCacheManager.deleteTree
        5. xPDOCacheManager.endsWith
        6. xPDOCacheManager.escapeSingleQuotes
        7. xPDOCacheManager.get
        8. xPDOCacheManager.getCachePath
        9. xPDOCacheManager.getCacheProvider
        10. xPDOCacheManager.matches
        11. xPDOCacheManager.replace
        12. xPDOCacheManager.set
        13. xPDOCacheManager.writeFile
        14. xPDOCacheManager.writeTree
      3. xPDOGenerator
        1. xPDOGenerator.parseSchema
        2. xPDOGenerator.writeSchema
      4. xPDOManager
        1. xPDOManager.createObjectContainer
        2. xPDOManager.createSourceContainer
        3. xPDOManager.removeObjectContainer
        4. xPDOManager.removeSourceContainer
      5. xPDOObject
        1. Configuration Accessors
          1. getOption
          2. setOption
        2. Field Accessors
          1. fromArray
          2. fromJSON
          3. get
          4. set
          5. toArray
          6. toJSON
        3. Metadata Accessors
          1. getFieldName
          2. getFKClass
          3. getFKDefinition
          4. getPK
          5. getPKType
          6. getSelectColumns
        4. Persistence Methods
          1. remove
          2. save
        5. Related Object Accessors
          1. addMany
          2. addOne
          3. getMany
          4. getOne
        6. State Accessors
          1. isDirty
          2. isLazy
          3. isNew
        7. Static Object Loaders
          1. _loadCollectionInstance
          2. _loadInstance
          3. _loadRows
          4. load
          5. loadCollection
          6. loadCollectionGraph
          7. Using Custom Loader Classes
        8. Validation
          1. addValidationRule
          2. getValidator
          3. isValidated
          4. removeValidationRules
          5. validate
      6. xPDOQuery
        1. xPDOQuery.andCondition
        2. xPDOQuery.groupby
        3. xPDOQuery.innerJoin
        4. xPDOQuery.leftJoin
        5. xPDOQuery.limit
        6. xPDOQuery.orCondition
        7. xPDOQuery.rightJoin
        8. xPDOQuery.select
        9. xPDOQuery.setClassAlias
        10. xPDOQuery.sortby
        11. xPDOQuery.where
      7. xPDORevisionControl
      8. xPDOTransport
        1. xPDOTransport.install
        2. xPDOTransport.pack
        3. xPDOTransport.uninstall
      9. xPDOValidator
        1. xPDOValidator.addMessage
        2. xPDOValidator.getMessages
        3. xPDOValidator.hasMessages
        4. xPDOValidator.validate

The xPDO Constructor

default xPDO connection constructor
$xpdo= new xPDO($dsn, $username= '', $password= '', $options= array(), $driverOptions= null) 

Parameters

As you can see, there are 5 parameters available in the constructor; the only necessary one is the first:

$dsn

This parameter asks you for your DSN value, which is formatted like so:

mysql:host=MYHOSTNAME;dbname=MYDBNAME;charset=MYCHARSET

You'll simply have to change the values of the hostname, database name, and charset to set up the parameter. More info can be found at PHP.net's PDO page.

$username and $password

This is the username and password to the database. Simply specify the database login information you'd like to use for xPDO's connections.

$options

This allows you to pass an array of xPDO-specific options into the constructor.

Some of the xPDO-specific parameters use custom defines that you can use, such as (but not limited to):

  • xPDO::OPT_BASE_CLASSES — An array of classes to load upon instantiation.
  • xPDO::OPT_BASE_PACKAGES — A comma-separated string of package names/paths (separated by a colon) to be loaded upon instantiation.
  • xPDO::OPT_CACHE_COMPRESS — If set, any xPDOCache instances using providers that support compressing data will use that option by default.
  • xPDO::OPT_CACHE_DB — If set, database result set caching will be enabled.
  • xPDO::OPT_CACHE_DB_COLLECTIONS — If set, database result set caching will attempt to cache entire collections.
  • xPDO::OPT_CACHE_DB_OBJECTS_BY_PK — If set, database result set caching will create cache entries by primary key in addition to the query signature used.
  • xPDO::OPT_CACHE_DB_EXPIRES — If set, defines the number of seconds a database result set cache entry is valid in the cache; 0 means it does not expire.
  • xPDO::OPT_CACHE_DB_HANDLER — If set, defines an xPDOCache derivative to handle database result set caching.
  • xPDO::OPT_CACHE_EXPIRES — If set, defines the number of seconds a cache entry is valid in any cache provider by default; 0 means it does not expire.
  • xPDO::OPT_CACHE_FORMAT — If set, defines the format cache files are stored in when using xPDOFileCache; the default is PHP, but JSON and serialized are available. (2.1 only)
  • xPDO::OPT_CACHE_KEY — If set, defines the key of the default cache instance; the default value is default.
  • xPDO::OPT_CACHE_PATH — If set, will set a custom cachePath class variable to the xPDO object that can be used in caching.
  • xPDO::OPT_CACHE_ATTEMPTS — If set, defines the number attempts xPDOFileCache will attempt to lock an existing cache entry for writing; default is 1. (2.1 only)
  • xPDO::OPT_CACHE_ATTEMPT_DELAY — If set, defines the number microseconds to delay each attempt to lock existing cache entries for writing; default is 10000. (2.1 only)
  • xPDO::OPT_CONNECTIONS — Optionally defines a pool of additional connections to select from when instantiating xPDO. (2.2 only)
  • xPDO::OPT_CONN_INIT — Defines options a connection must have to be selected as the initial connection; applicable when multiple connections are defined. (2.2 only)
  • xPDO::OPT_CONN_MUTABLE — Defines if data from a connection can be changed, i.e. is writable. (2.2 only)
  • xPDO::OPT_HYDRATE_FIELDS — If true, fields will be hydrated.
  • xPDO::OPT_HYDRATE_RELATED_OBJECTS — If true, related objects will be hydrated.
  • xPDO::OPT_HYDRATE_ADHOC_FIELDS — If true, ad-hoc fields will be hydrated.
  • xPDO::OPT_LOADER_CLASSES — Can be an array of class names to load upon instantiation of the xPDO object. (deprecated in 2.0.0-pl)
  • xPDO::OPT_ON_SET_STRIPSLASHES — If set, stripslashes() is applied to values being set() on xPDOObject instances.
  • xPDO::OPT_TABLE_PREFIX — If set, all database class references will be prefixed with this prefix.
  • xPDO::OPT_VALIDATOR_CLASS — If set, will use a custom class specified that derives from xPDOValidator (the default)
  • xPDO::OPT_VALIDATE_ON_SAVE — If true, xPDOObjects will be validated against their Validators before saving.

$driverOptions

An optional array of driver-specific PDO options. More info can be found here.

See Also

More information about options

  1. Hydrating Fields

Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab) or become an editor of the MODX Documentation.