英文:
SQL statement to delete a user in moodle
问题
You can use the following SQL statement to delete a user in Moodle:
"从 mdl_user 表中删除 id=1234 的用户。"
英文:
Which SQL statement can I use to delete a user in moodle. I don't think
"delete from mdl_user where id=1234"
is insufficient.
Thanks
答案1
得分: 1
我不建议通过SQL删除用户
有许多内部检查和事件触发器,以及破坏数据库完整性的可能性
手动删除用户
站点管理员 > 用户 > 浏览用户列表 > [选择要删除的用户]
同时删除多个用户
如果您需要同时删除多个用户,可以使用CSV文件
创建一个像这样的CSV文件,将deleted
列中设置为1
username,firstname,lastname,email,deleted
student1,Student,One,s1@example.com,1
您可以使用SQL构建CSV文件
从mdl_user中选择username,firstname,lastname,email,1 AS deleted
WHERE ...
然后转到站点管理员 > 用户 > 上传用户
选择“更新现有用户”作为上传类型
以及“是”作为允许删除
通过命令行删除用户
有一个名为Moosh的命令行工具,允许从命令行中删除用户
moosh user-delete username1 username2
Moosh不包含在Moodle中,因此您需要安装它
用于删除用户的PHP代码
或者创建一些使用Moodle函数delete_user()
删除用户的代码
$sql = "SELECT *
FROM {user}
WHERE ...";
$users = $DB->get_records_sql($sql);
foreach ($users as $user) {
delete_user($user);
}
英文:
I wouldn't recommend deleting a user via SQL
There are lots of internal checks and event triggers, as well as the likelihood of breaking database integrity
Delete a user manually
Site admin > Users > Browse list of users > [select user to delete]
Delete several users at a time
If you need to delete several users at a time then you can use a csv file
Create a csv file like this with 1 in the deleted
column
username,firstname,lastname,email,deleted
student1,Student,One,s1@example.com,1
You could use SQL to build the csv
SELECT username,firstname,lastname,email,1 AS deleted
FROM mdl_user
WHERE ...
Then go to Site admin > Users > Upload users
Select "Update existing users" for Upload type
and "Yes" for Allow deletes
Delete users via command line
There is a command line tool called Moosh that allows deletion from the command line
moosh user-delete username1 username2
Moosh isn't included with Moodle so you will need to install it
PHP code to delete a user
Or create some code to delete users using the Moodle function delete_user()
$sql = "SELECT *
FROM {user}
WHERE ...";
$users = $DB->get_records_sql($sql);
foreach ($users as $user) {
delete_user($user);
}
答案2
得分: 0
在Moodle中,没有用于删除用户的SQL语句 - 有太多不同的步骤需要采取才能正确删除用户,因此您应始终使用用于删除用户的PHP函数。
如果您需要从Moodle之外执行此操作,那么您应该考虑配置并使用“core_user_delete_users” webservice函数。
请参阅https://docs.moodle.org/en/Using_web_services以获取有关如何使用webservice函数与您的Moodle服务器通信的详细信息。
英文:
There is no SQL statement for deleting a user in Moodle - there are far too many different steps that are taken in order to properly delete a user, so you should always use the PHP function for deleting users.
If you need to do this from outside of Moodle itself, then you should look at configuring and using the "core_user_delete_users" webservice function.
See https://docs.moodle.org/en/Using_web_services for details of how to use webservice functions to communicate with your Moodle server.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论