Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Data definition API: Difference between revisions

From MoodleDocs
m (link edit)
Line 12: Line 12:
* This directory is included automatically both by the installation and the upgrade processes and it shouldn't be used ever out from those parts of Moodle.
* This directory is included automatically both by the installation and the upgrade processes and it shouldn't be used ever out from those parts of Moodle.
* Don't forget to read carefully the complete documentation about [[XMLDB Creating new DDL functions|creating new DDL functions]] before playing with these functions. Everything is explained there, with one general example and some really useful tricks to improve the use of all the functions detailed below.
* Don't forget to read carefully the complete documentation about [[XMLDB Creating new DDL functions|creating new DDL functions]] before playing with these functions. Everything is explained there, with one general example and some really useful tricks to improve the use of all the functions detailed below.
* If you want real examples of the usage of these functions it's highly recommended to examine the '''upgrade.php''' scripts that are responsibles for Moodle upgrading since the 1.7 release. Also, it's very good idea to use the [[XMLDB Editor]] to generate automatically the desired PHP code. Play with it!


== The functions ==
== The functions ==

Revision as of 23:14, 3 December 2007

Starting with Moodle 1.7, an important change has been done to practically all the DB abstraction layer in order to improve the number of RDBMS supported by Moodle.

One of the basic points to achieve this improvement is to have a well-defined group of functions able to handle all the DB structure (DDL statements) using one neutral description, being able to execute the correct SQL statements required by each RDBMS. All these functions are used exclusively by the installation and upgrade processes.

In this page you'll see a complete list of such functions, with some explanations, tricks and examples of their use. If you are interested, it's also highly recommendable to take a look to the DML functions page where everything about how to handle DB data (select, insert, update, delete i.e. DML statements) is defined.

Of course, feel free to clarify, complete and add more info to all this documentation. It will be welcome, absolutely!

Main info

  • All the functions in this page are present in the "lib/ddllib.php" file under Moodle root directory.
  • This directory is included automatically both by the installation and the upgrade processes and it shouldn't be used ever out from those parts of Moodle.
  • Don't forget to read carefully the complete documentation about creating new DDL functions before playing with these functions. Everything is explained there, with one general example and some really useful tricks to improve the use of all the functions detailed below.
  • If you want real examples of the usage of these functions it's highly recommended to examine the upgrade.php scripts that are responsibles for Moodle upgrading since the 1.7 release. Also, it's very good idea to use the XMLDB Editor to generate automatically the desired PHP code. Play with it!

The functions

See also

  • XMLDB Documentation: Main page of the whole XMLDB documentation, where all the process is defined and all the related information resides.
  • XMLDB Defining one XML structure: Where you will know a bit more about the underlying XML structure used to define the DB objects, that is used continuously by the functions described in this page.
  • DML functions: Where all the functions used to handle DB data (DML) are defined.