Delete all users

Permalink
Hi! I've got a site with more than 4000 users and I want to delete them all (except from the admin user).

Surely I nedd some php code but could something like this work?

<?php
mysql_connect("host", "user", "pass");
@mysql_select_db("dbname") or die( "Unable to select database");
$query="SELECT * FROM users";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
    $id=mys ql_result($result,$i,"uID")
    $u = UserInfo::getByID($id);
    UserInfo::delete($u);
    $i++;
}   
?>


Thanks!

 
ScottC replied on at Permalink Reply
ScottC
but I wouldn't start at 0 since 1 is your admin ;).
AlbertoB replied on at Permalink Reply
thanks for the advice, but I was planning doing exactly that, delete all the users except the admin.

I'm trying with this piece of code(after connecting with my DB)
<?php
$i=0;
while ($i < $num){
$name=mysql_result($result,$i,"uName");
$idnum=mysql_result($result,$i,"uID");
if ( ($name == 'admin') ){
    echo ('Admin<br>');      
}else{
    $u = UserInfo::getByID($idnum);  
    // maybe?? $u = User::getByUserID($idnum);         
    $pr=UserInfo::delete();         
    }
}
?>


but I have some errors, any advice?
renic replied on at Permalink Reply
renic
http://dev.mysql.com/doc/refman/5.0/en/delete.html

http://us3.php.net/function.mysql-query...

You just run a mysql query to remove the rows that aren't your admin account.

mysql_query("DELETE * FROM $myTable WHERE uID != '$admin'");
AlbertoB replied on at Permalink Reply
and that was my first approach too, but then I was afraid and asked myself if there are no dependencies between other tables...

I just have to delete the rows in the table Users or also update UserAttributeKeys, UserAttributeValues, UserGroups, UserValidationHashes or others?

Thanks for your answer and for the links!
renic replied on at Permalink Reply
renic
would be wise to edit them all if you are doing it by hand...

would probably be better to see how the existing code handles a single user deletion, so that you don't miss anything.

make sure you backup first... manually editing databases is surefire way to break things the first few times.

does it need to be done in the script, or can you handle it from another program (like phpmyadmin or from mysql in console)?
AlbertoB replied on at Permalink Reply
I tried to follow concrete's deletion routine but get lost (my php skills aren´t very good...)

Sure I have to make some backup of my DB and I want to delete the users, no matter the way (php script or phpmyadmin would be ok)