Get all users in moodle (2.x)
To get all users in moodle using the API(s), you can use the following snippet:
#! /user/bin/php
<?php
define('CLI_SCRIPT', true);
require_once('config.php');
// if you call DB inside a function, you'll need:
// global $DB;
$allusers = $DB->get_records('user');
foreach($allusers as $user) {
echo "User id $user->id is $user->username\n";
}
?>
#! /user/bin/php
<?php
define('CLI_SCRIPT', true);
require_once('config.php');
// if you call DB inside a function, you'll need:
// global $DB;
$allusers = $DB->get_records('user');
foreach($allusers as $user) {
echo "User id $user->id is $user->username\n";
}
?>