Reset users

 * Delete all users except uid 0 and 1.
 * Reset auto increment on users table.
function _MY_MODULE_delete_users() {
  // Delete.
  $uids = db_select('users', 'u')
  ->fields('u', array('uid'))
  ->condition('uid', array(0, 1), 'NOT IN')


  // Reset auto increment.
  db_query("ALTER TABLE users AUTO_INCREMENT = 1"); 
  // Users table doesn't use AI, reset uid sequence.
  db_query("UPDATE sequences SET value = 1");
  db_query("ALTER TABLE sequences AUTO_INCREMENT = 1");
  return 'User_delete_multiple is void, check for success manually';

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.