Publié
2006-11-11 04:28
CiviCRM uses the PEAR package DB_DataObject to access the mysql database. Doing so reduces the amount of sql we need to write to fetch / store values for a single table. For queries involving more than one table, we write them manually since since it was fairly painful to try to force complicated queries using DB_DataObject (we did use DB_DO for multiple table queries when we wrote EmailNow, in the end we felt the hoops we had to jump through was not worth the effort and hence the current scheme)
The basic PHP classes that represent a table are called DAO's (Data Access Objects). These are generated automatically by (xml/GenCode.php) which also generates the sql structure for that specific table. The xml files representing the schema is stored under CIVCRM_ROOT/xml/schema. The sql file generated (civicrm_41.mysql and civicrm_40.mysql) are stored under CIVICRM_ROOT/sql (note that the generated files are not present in the svn repository). The DAO files are stored under CIVICRM_ROOT/CRM/Core/DAO (and under appropriate directories based on what table it is, this is configured in the xml representation.
Each table has the following properties
- base: The directory where the DAO class is stored
- class: The name of the PHP Class. Since PHP does have very good namespace support, we follow the PEAR convention of naming classes as a combination of directory and class names. Thus the table civicrm_domain has a class name of CRM_Core_DAO_Domain
- name: The table name
- comment: The comment field
- add: The CiviCRM version when this table was added to the schema
- drop: The CiviCRM version when this table was dropped from the schema
- name: The name of the field
- title: The title of the field. Used in various selectors in import/export etc
- type: The sql type of this field, possible options include varchar, text, int, boolean, decimal, date, datetime, enum
- length: The length of the field if its of type varchar
- default: The default value for this field
- required: If this field is required
- import: If this field can be imported
- export: If this field can be exported
- log: If any modifications to this field should be logged
- rule: A validation rule for this field
- add: The CiviCRM version when this field was added to the schema
- drop: The CiviCRM version when this field was dropped from the schema
- static $_tableName: The name of the table it represents
- static $_fields: The columns that make up this table (along with the above values that are encoded in the xml as described above
- static $_links: The foreign key relationships that this table has
- $fieldName: An entry for each column in the table
Filed under
Comments
Hey,
Is this still accurate as the most authoritative first place to start for understanding CiviCRM architecture, up to and including 3.2beta?
I'm aware of the updated ERD database diagram at http://civicrm.org/blogs/mbriney/contacts-erd-v31
This is the closest I can find to a documentation front page on DAO, BAO etc (I may be looking in the wrong places). http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Architecture leads to this blog series!
feel free to ask us questions or clarifications on IRC
lobo