我在moodle中写入数据库时遇到错误:
代码:
if (is_siteadmin()) {
class addschedule_form extends moodleform {
function definition () {
$mform =& $this->_form;
$mform->addElement('text', 'id', 'Enter ID:');
$mform->setType('id', PARAM_TEXT);
$this->add_action_buttons(true, 'submit');
}
}
$ti_form = new addschedule_form();
$ti_form->get_data();
if ($ti_form->is_cancelled()) {redirect('index.php');}
if ($recs = $ti_form->get_data()) {
$deleteit = $DB -> delete_records('DELETE * FROM `mdl_schedules` WHERE id = ' . $recs -> id . '');
redirect('schedule.php');
}
}
else { }
$ti_form->display();
可能是什么原因?任何参考或帮助将不胜感激。
此致
答案 0 :(得分:2)
语法是
$DB->delete_records('schedules', array('id' => $recs->id));
您可能希望在标签中保持此选项以供参考 - https://docs.moodle.org/dev/Data_manipulation_API