Moodle Notes-базы данных операций

Для получения дополнительной информации, пожалуйста, смотрите: https://www.cnblogs.com/lichihua/p/5706285.html

<?php

require_once('../config.php'); // config.php under root folder

require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->libdir .'/filelib.php');

//redirect_if_major_upgrade_required();

Подробные параметры

// Посмотрим, сколько записей соответствует заданным критериям
// ountcount_records: $ DB-> count_records ($ таблица, массив $ condition = null)

// статистические функции, эквивалентные: SELECT COUNT (*) из mdl_user; эхо $ db-> count_records ( 'пользователя') '<br> <br>'; // число запросов пользователей.

// ② $ DB-> count_records_select ($ таблица, $ select, массив $ params = null, $ countitem = "COUNT ('x')")

// Примечание: COUNT ('x') эквивалентно COUNT (*) echo $ DB-> count_records_select ('user', 'firstname =?', Array ('classmate'), "COUNT ('x')"). '

 

Операция структуры базы данных:

https://docs.moodle.org/dev/Data_definition_API

function xmldb_xxxx_upgrade {
 
    global $DB;
 
    $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
 
    /// Your upgrade code goes here
}

 

Таблица технических данных:

/// To detect if one table exists:
    $dbman->table_exists($table)
 
/// To create one table:
    $dbman->create_table($table, $continue=true, $feedback=true)
 
/// To drop one table:
    $dbman->drop_table($table, $continue=true, $feedback=true)
 
/// To rename one table:
    $dbman->rename_table($table, $newname, $continue=true, $feedback=true)

Поле данных операции:

/// To detect if one field exists:
    $dbman->field_exists($table, $field)
 
/// To create one field:
    $dbman->add_field($table, $field, $continue=true, $feedback=true)
 
/// To drop one field:
    $dbman->drop_field($table, $field, $continue=true, $feedback=true)
 
/// To change the type of one field:
    $dbman->change_field_type($table, $field, $continue=true, $feedback=true)
 
/// To change the precision of one field:
    $dbman->change_field_precision($table, $field, $continue=true, $feedback=true)
 
/// To change the signed/unsigned status of one field:
    $dbman->change_field_unsigned($table, $field, $continue=true, $feedback=true)
 
/// To make one field nullable or not:
    $dbman->change_field_notnull($table, $field, $continue=true, $feedback=true)
 
/// To drop one enum (check constraint) from one field:
/// (note this function will be only available in Moodle 2.0 as it's needed
/// to drop any enum existing in previous Moodle releases). Will be out in Moodle 2.1
    $dbman->drop_enum_from_field($table, $field, $continue=true, $feedback=true)
 
/// To change the default value of one field:
    $dbman->change_field_default($table, $field, $continue=true, $feedback=true)
 
/// To rename one field:
    $dbman->rename_field($table, $field, $newname, $continue=true, $feedback=true)

Индекс работы:

/// To detect if one index exists:
    $dbman->index_exists($table, $index)
 
/// To return the name of one index in DB:
    $dbman->find_index_name($table, $index)
 
/// To add one index:
    $dbman->add_index($table, $index, $continue=true, $feedback=true)
 
/// To drop one index:
    $dbman->drop_index($table, $index, $continue=true, $feedback=true)

 

Опубликовано 150 оригинальных статей · Оценено 149 · 810 000 просмотров

рекомендация

отblog.csdn.net/chaishen10000/article/details/105391042