惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
S
SegmentFault 最新的问题
V
Visual Studio Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
美团技术团队
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
有赞技术团队
有赞技术团队
量子位
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
博客园 - 叶小钗
月光博客
月光博客
P
Proofpoint News Feed
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog

博客园 - 路者

几个开源Android Camera传输视频流例子 Moodle开发基础1 构建Moodle开发环境 Moodle二次开发(1)-- 微创新 让moodle增加学号 通信对象System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。 WCF传输List<object>时序列化问题 c# 类似于QQ表情弹出框功能的二种实现方法 asp.net类似于QQ表情弹出框功能的实现方法 仿QQ弹出窗口[转] 上海大学游戏设计07年硕士研究生招生考试大纲 海南 琼海 韵达快递 垃圾! 窗体显示中form1.Show()和form1.ShowDialog()的区别 集合概述 C#中的格式 同一解决方案内的多个项目之间如何引用? 什么是SDK? 每个开发人员现在应该下载的十种必备工具 关于asp.net中服务器应用程序不可用
Moodle: 查询 / 更新 / 添加 / 删除 / 导出 用户 ($DB用法
路者 · 2017-05-26 · via 博客园 - 路者

Moodle: 查询 / 更新 / 添加 / 删除 / 导出 用户 ($DB用法) 1. 添加用户 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(); $person = new StdClass(); $person->auth = 'manual'; $person->confirmed = 1; $person->mnethostid = 1; $person->lastlogin = time(); $person->currentlogin = time(); $person->username = "username"; $person->password = hash_internal_user_password('password'); //$person->idnumber = $person->username; $person->firstname = "firstname"; $person->lastname = "lastname"; $person->email = "firstname@gmail.com"; $person->city = "sf"; $person->country = "US"; $person->lang = "en"; echo $person->id = $DB->insert_record('user', $person); 复制代码 2. 查询用户 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(); echo $DB->count_records('user').'

'; // how many users do you have $person = $DB->get_record('user', array('username'=>'my_name')); echo '

'; print_r($person);
复制代码


3. 更新用户
Php代码
require_once('config.php');

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

//redirect_if_major_upgrade_required(); 

$person               = new StdClass();
$person->id           = 10370;
$person->password     = hash_internal_user_password('xinxin123');

$DB->update_record('user', $person);
复制代码


4. 删除用户
Php代码
require_once('config.php');

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

//redirect_if_major_upgrade_required(); 

$DB->delete_records('user', array('id'=>10546));
复制代码


5. 导出用户
Php代码
require_once('config.php');
require_once('../lib/functions.php');
require_once('../lib/array2xml.php');

$conditions = array();
$sort       = 'id desc';
$fields     = 'id,username,firstname,lastname,email,lastlogin,lastip';
$limitfrom  = 0;
$limitnum   = 30;

$students['students'] = objectToArray($DB->get_records('user', $conditions, $sort, $fields, $limitfrom, $limitnum));
//echo '
'; print_r($students);
//echo JSON($students);

header( 'Content-Type:text/html;charset=utf-8');
header('Content-type: text/xml'); 
exit(array2xml($students));
复制代码
转自:天梯梦iteye博客