<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADML_functions_-_pre_2.0</id>
	<title>Development:DML functions - pre 2.0 - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADML_functions_-_pre_2.0"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DML_functions_-_pre_2.0&amp;action=history"/>
	<updated>2026-05-07T00:58:25Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:DML_functions_-_pre_2.0&amp;diff=11006&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DML_functions_-_pre_2.0&amp;diff=11006&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:09Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:DML_functions_-_pre_2.0&amp;diff=11005&amp;oldid=prev</id>
		<title>1&gt;Gmccullagh@gmail.com: /* The functions */ updated to make this a little more readabable and have a contents for quick access</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DML_functions_-_pre_2.0&amp;diff=11005&amp;oldid=prev"/>
		<updated>2008-10-20T14:57:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;The functions: &lt;/span&gt; updated to make this a little more readabable and have a contents for quick access&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&amp;#039;&amp;#039;&amp;#039;Important note:&amp;#039;&amp;#039;&amp;#039; This article contains information valid for versions before Moodle 2.0, so should be considered &amp;#039;&amp;#039;&amp;#039;deprecated&amp;#039;&amp;#039;&amp;#039;. If you want to see up to date information, please go to [[Development:DML functions|DML functions]] instead.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this page you&amp;#039;ll access to the available functions under Moodle to be able to access to DB data. You should use &amp;#039;&amp;#039;&amp;#039;exclusively&amp;#039;&amp;#039;&amp;#039; these functions in order to retrieve or modify DB contents because these functions provide an high level of abstraction and guarantee that your DB manipulation will work against different RDBMS.&lt;br /&gt;
&lt;br /&gt;
Where possible, tricks and examples will be documented here in order to make developers&amp;#039;s life a bit easier. Of course, feel free to clarify, complete and add more info to all this documentation. It will be welcome, absolutely!&lt;br /&gt;
&lt;br /&gt;
== Main info ==&lt;br /&gt;
&lt;br /&gt;
== The functions ==&lt;br /&gt;
&lt;br /&gt;
=== Seeing if any records exist match a given criteria ===&lt;br /&gt;
&lt;br /&gt;
          o record_exists($table, $field1=&amp;#039;&amp;#039;, $value1=&amp;#039;&amp;#039;, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;) &lt;br /&gt;
            Test whether a record exists in a table where all the given fields match the given values.&lt;br /&gt;
          o record_exists_select($table, $select=&amp;#039;&amp;#039;) &lt;br /&gt;
            Test whether any records exists in a table which match a particular WHERE clause.&lt;br /&gt;
          o record_exists_sql($sql) &lt;br /&gt;
            Test whether a SQL SELECT statement returns any records.&lt;br /&gt;
&lt;br /&gt;
=== Seeing how many records match a given criteria ===&lt;br /&gt;
&lt;br /&gt;
          o count_records($table, $field1=&amp;#039;&amp;#039;, $value1=&amp;#039;&amp;#039;, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;) &lt;br /&gt;
            Count the records in a table where all the given fields match the given values.&lt;br /&gt;
          o count_records_select($table, $select=&amp;#039;&amp;#039;, $countitem=&amp;#039;COUNT(*)&amp;#039;) &lt;br /&gt;
            Count the records in a table which match a particular WHERE clause.&lt;br /&gt;
          o count_records_sql($sql) &lt;br /&gt;
            Get the result of a SQL SELECT COUNT(...) query.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving a single record ===&lt;br /&gt;
&lt;br /&gt;
          o get_record($table, $field1, $value1, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;) &lt;br /&gt;
            Get a single record as an object&lt;br /&gt;
          o get_record_select($table, $select=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;) &lt;br /&gt;
            Gets one record from a table, as an object&lt;br /&gt;
          o get_record_sql($sql, $expectmultiple=false, $nolimit=false) &lt;br /&gt;
            Get a single record as an object using an SQL statement&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Getting an array of records ===&lt;br /&gt;
&lt;br /&gt;
          o get_records($table, $field=&amp;#039;&amp;#039;, $value=&amp;#039;&amp;#039;, $sort=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;, $limitfrom=&amp;#039;&amp;#039;, $limitnum=&amp;#039;&amp;#039;) &lt;br /&gt;
            Get a number of records as an array of objects.&lt;br /&gt;
          o get_records_select($table, $select=&amp;#039;&amp;#039;, $sort=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;, $limitfrom=&amp;#039;&amp;#039;, $limitnum=&amp;#039;&amp;#039;) &lt;br /&gt;
            Get a number of records as an array of objects.&lt;br /&gt;
          o get_records_list($table, $field=&amp;#039;&amp;#039;, $values=&amp;#039;&amp;#039;, $sort=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;, $limitfrom=&amp;#039;&amp;#039;, $limitnum=&amp;#039;&amp;#039;) &lt;br /&gt;
            Get a number of records as an array of objects.&lt;br /&gt;
          o get_records_sql($sql, $limitfrom=&amp;#039;&amp;#039;, $limitnum=&amp;#039;&amp;#039;) &lt;br /&gt;
            Get a number of records as an array of objects.&lt;br /&gt;
          o get_records_menu($table, $field=&amp;#039;&amp;#039;, $value=&amp;#039;&amp;#039;, $sort=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;) &lt;br /&gt;
            Get the first two columns from a number of records as an associative array.&lt;br /&gt;
          o get_records_select_menu($table, $select=&amp;#039;&amp;#039;, $sort=&amp;#039;&amp;#039;, $fields=&amp;#039;*&amp;#039;) &lt;br /&gt;
            Get the first two columns from a number of records as an associative array.&lt;br /&gt;
          o get_records_sql_menu($sql) &lt;br /&gt;
            Get the first two columns from a number of records as an associative array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Getting a particular field from the database ===&lt;br /&gt;
&lt;br /&gt;
          o get_field($table, $return, $field1, $value1, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;) &lt;br /&gt;
            Get a single value from a table row where all the given fields match the given values.&lt;br /&gt;
          o get_field_select($table, $return, $select) &lt;br /&gt;
            Get a single value from a table row where a particular select clause is true.&lt;br /&gt;
          o get_field_sql($sql) &lt;br /&gt;
            Get a single value from a table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Setting a particular field in the database ===&lt;br /&gt;
&lt;br /&gt;
          o set_field($table, $newfield, $newvalue, $field1, $value1, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;) &lt;br /&gt;
            Set a single field in every table row where all the given fields match the given values.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Deleting Records===&lt;br /&gt;
&lt;br /&gt;
          o delete_records($table, $field1=&amp;#039;&amp;#039;, $value1=&amp;#039;&amp;#039;, $field2=&amp;#039;&amp;#039;, $value2=&amp;#039;&amp;#039;, $field3=&amp;#039;&amp;#039;, $value3=&amp;#039;&amp;#039;) &lt;br /&gt;
            Delete the records from a table where all the given fields match the given values.&lt;br /&gt;
          o delete_records_select($table, $select=&amp;#039;&amp;#039;) &lt;br /&gt;
            Delete one or more records from a table&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Inserting Records===&lt;br /&gt;
&lt;br /&gt;
          o insert_record($table, $dataobject, $returnid=true, $primarykey=&amp;#039;id&amp;#039;) &lt;br /&gt;
            Insert a record into a table and return the &amp;quot;id&amp;quot; field if required&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updating Records===&lt;br /&gt;
&lt;br /&gt;
          o update_record($table, $dataobject) &lt;br /&gt;
            Update a record in a table&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:DDL functions]]: Up to date information about DDL functions.&lt;br /&gt;
* [[Development:DML functions]]: Up to date information about DML functions.&lt;br /&gt;
* [[Development:DDL functions - pre 2.0]]: &amp;#039;&amp;#039;&amp;#039;(deprecated!)&amp;#039;&amp;#039;&amp;#039; Where all the functions used to handle DB objects ([[wikipedia:Data_Definition_Language|DDL]]) are defined .&lt;br /&gt;
* [[Development:DB layer 2.0 migration docs|DB layer 2.0 migration docs]]: Information about how to modify your code to work with the new Moodle 2.0 DB layer.&lt;br /&gt;
&lt;br /&gt;
[[Category:DB]]&lt;br /&gt;
[[Category:XMLDB]]&lt;/div&gt;</summary>
		<author><name>1&gt;Gmccullagh@gmail.com</name></author>
	</entry>
</feed>