1
wcrwcr
Is there a query to add users in a batch?
  • 2009/4/9 18:55

  • wcrwcr

  • Home away from home

  • Posts: 1114

  • Since: 2003/12/12


Hi all

I remember of reading that already somewhere but after some search I could not find any input, so:

Can I add a bunch of users in a batch running any kind of sql query?

If so, can you guys point me the right direction or the query itself?
(BTW > i´m not a coder )

Thnak you all



2
Burning
Re: Is there a query to add users in a batch?
  • 2009/4/9 19:14

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

You should test this script

// christian@frxoops.org - http://www.frxoops.org
// Import users from a csv or text file into XOOPS 2.3.2
// variables
$bdd"bdd-name";
$host"localhost";
$user"root";
$pass"";
$prefix"xc2234"// tables prefix, without _
$separator ";";//separator used in original file 
$regdate=time();
$fichier "file-name.csv"// file name to read


// IMPORTANT : DO NOT LEAVE AN EMPTY LINE IN YOUR ORIGINAL DOCUMENT (file-name.csv)

mysql_connect($host,$user,$pass) or die("Unable to connect Database");
mysql_select_db($bdd);

//Open file for read 
if (file_exists($fichier))
$fp fopen("$fichier""r");
else{ 
// unknown file 
echo "File not found !Import stopped.";
exit();
}
echo 
'Begin file import : '.$fichier.''
;
echo 
'';
echo 
'UIDPseudo';
// import line by line 
while (!feof($fp)){
$ligne fgets($fp,4096);
$liste explode($separator,$ligne); //create array 



// Add real name
$uname $liste[0];
// End

// Add website
$url $liste[1];
// End

// Add avatar
$user_avatar $liste[2];
// End

// Add "From" info
$user_from "xoops.org";
// End

// Add Sign
$user_sig $liste[3];
// End

// Add Password
$passmd5(trim($liste[4])); 
// End

$rank "1"// Choose rank

// Add occupation
$user_occ "Xoops Designer";
// End



$user_mailok "1"// Choose 1 if you allow administrator to send email


// Add user in xoops_users table
$query "insert into ".$prefix."_users (uname, url, user_avatar, user_regdate, user_from, user_sig, pass, rank, user_occ, user_mailok) VALUES ('".$uname."', '".$url."', '".$user_avatar."', '".$regdate."', '".$user_from."', '".$user_sig."', '".$pass."', '".$rank."', '".$user_occ."', ".$user_mailok.")";

$resultmysql_query($query);
$uid mysql_insert_id();

//Add user in group : registered users per default
$numgroup ='2';// choose Group number
$query "insert into ".$prefix."_groups_users_link (groupid, uid) VALUES('".$numgroup."', '".$uid."')";
$resultmysql_query($query);

if (
mysql_error()){
echo 
"Error in database : ".mysql_error();
echo 
"Importation stoppée.";
fclose($fp);
exit();
}else{
echo 
" ".$uid."  ".$uname."  ";
}
}

echo 
"Import finished successfully.";// That's ok !

fclose($fp);
?>


Found on frxoops forums for months (I can't find link anymore). It works fine with XOOPS 2.3.2

You have to customize some informations (comments translated by me, sorry )
Still learning CSS and... english

3
wcrwcr
Re: Is there a query to add users in a batch?
  • 2009/4/9 19:20

  • wcrwcr

  • Home away from home

  • Posts: 1114

  • Since: 2003/12/12


thanks Burning

Do you have an idea how to run it because it´s not a query but a php file isn´t it?

Did you tested it on a XOOPS 20182 too?

4
Burning
Re: Is there a query to add users in a batch?
  • 2009/4/9 19:29

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


I'm not sure that it works for XOOPS 2.0.18

I will search on frxoops original link (because original script was made for XOOPS 2.0.18 if I can remember).


To use this script it is very simple (I'm not a coder but I have been able to make it work) :

1. You have to create a table in your favorite software like Miscrosoft Excel (.xls file) or Open Office (.odt file). Each column have to exist and listed like this :
uname, url, user_avatar, user_regdate, user_from, user_sig, pass, rank, user_occ, user_mailok
If you want less or more information to be imported, modify import script.

2. export this table with .csv extension

3. Put script above (for example .my-import.php) and your .csv file in root path (www/your-site/)

4. run script : http://localhost/your-site/my-import.php


Be sure to save your original database !! Many attempts could be necessary
Still learning CSS and... english

5
Burning
Re: Is there a query to add users in a batch?
  • 2009/4/9 19:36

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


Same thing for XOOPS 2.0.18, with less information to import.

// christian@frxoops.org - http://www.frxoops.org
// Import users from a csv or text file into XOOPS 2.0.18
// variables
$bdd"nom de la base";
$host"localhost";
$user"utilisateur de la base";
$pass"mot de passe de la base";
$prefix"préfixe"//préfixe des tables, sans indiquer le _
$separator ";";//séparateur uilisé dans le fichier à importer
$regdate=time();
$fichier "membres.txt"//nom du fichier à parcourir
//file structure : pseudo;email;password en clair

//ne pas laisser de ligne vide à la fin du fichier à importer

mysql_connect($host,$user,$pass) or die("Unable to connect Database");
mysql_select_db($bdd);

//Open file for read - Ouverture du fichier contenant les membres
if (file_exists($fichier))
$fp fopen("$fichier""r");
else{ 
// unknown file - fichier non trouvé
echo "File not found !Import stopped.";
exit();
}
echo 
'Begin file import : '.$fichier.''
;
echo 
'';
echo 
'UIDPseudo';
// import line by line - import ligne par ligne
while (!feof($fp)){
$ligne fgets($fp,4096);
$liste explode($separator,$ligne); //create array 
$uname $liste[0];
$email $liste[1];
$passmd5(trim($liste[2])); 
$user_mailok "0"//n'autorise pas l'administrateur à envoyer des mails par défaut - mettre à un (1) dans le cas contraire

// Add user in xoops_users table
$query "insert into ".$prefix."_users (uname, email, pass, user_regdate, user_mailok) VALUES ('".$uname."', '".$email."', '".$pass."', '".$regdate."' , ".$user_mailok.")";
$resultmysql_query($query);
$uid mysql_insert_id();

//Add user in group : registered users / utilisateurs enregistrés
$numgroup ='2';//changer cette valeur pour affecter le membre à un autre groupe
$query "insert into ".$prefix."_groups_users_link (groupid, uid) VALUES('".$numgroup."', '".$uid."')";
$resultmysql_query($query);

if (
mysql_error()){
echo 
"Error in database : ".mysql_error();
echo 
"Importation stoppée.";
fclose($fp);
exit();
}else{
echo 
" ".$uid."  ".$uname."  ";
}
}

echo 
"Import finished successfully.";//Import réalisé avec succès

fclose($fp);
?>

Still learning CSS and... english

6
wcrwcr
Re: Is there a query to add users in a batch?
  • 2009/4/9 19:54

  • wcrwcr

  • Home away from home

  • Posts: 1114

  • Since: 2003/12/12


Many thanks Burning!

I´ll try It ASAP

I guess that will be a nice feature to be in hand or even in te core.


7
seesoe
Re: Is there a query to add users in a batch?
  • 2009/7/29 16:58

  • seesoe

  • Just popping in

  • Posts: 33

  • Since: 2007/1/3 4


will this work in 2.3.3?

8
planetexcel
Re: Is there a query to add users in a batch?

Can this work for 2.4.1?

9
Burning
Re: Is there a query to add users in a batch?
  • 2009/12/9 13:16

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

Not tested with XOOPS 2.4.x

You should try first script, witch worked fine with XOOPS 2.3.x

10
planetexcel
Re: Is there a query to add users in a batch?

Quote:
// christian@frxoops.org - http://www.frxoops.org
// Import users from a csv or text file into XOOPS 2.3.2
// variables
$bdd= "----";
$host= "localhost";
$user= "-------";
$pass= "-----";
$prefix= "-----"; // tables prefix, without _
$separator = ";";//separator used in original file
$regdate=time();
$fichier = "myimp.csv"; // file name to read


// IMPORTANT : DO NOT LEAVE AN EMPTY LINE IN YOUR ORIGINAL DOCUMENT (file-name.csv)

mysql_connect($host,$user,$pass) or die("Unable to connect Database");
mysql_select_db($bdd);

//Open file for read
if (file_exists($fichier))
$fp = fopen("$fichier", "r");
else{ // unknown file
echo "File not found !
Import stopped.";
exit();
}
echo 'Begin file import : '.$fichier.'

';
echo '';
echo '';
// import line by line
while (!feof($fp)){
$ligne = fgets($fp,4096);
$liste = explode($separator,$ligne); //create array


// Add real name
$name = $liste[0];
// End

// Add real name
$uname = $liste[1];
// End

// Add real name
$email = $liste[2];
// End

// Add Password
$pass= md5(trim($liste[5]));
// End

// Add website
$url = $liste[3];
// End

// Add website
$user_regdate = $liste[4];
// End

// Add avatar
$user_avatar = "blank.gif";
// End

$rank = "1"; // Choose rank

$attachsig = "1";

$user_mailok = "1"; // Choose 1 if you allow administrator to send email


// Add user in xoops_users table
$query = "insert into ".$prefix."_users (name, uname, url, user_avatar, user_regdate, user_from, user_sig, pass, rank, user_occ, user_mailok, email) VALUES ('".$name."','".$uname."', '".$email."','".$url."', '".$user_avatar."', '".$regdate."', '".$user_from."', '".$user_sig."', '".$pass."', '".$rank."', '".$user_occ."', '".$user_mailok."')";

$result= mysql_query($query);
$uid = mysql_insert_id();

//Add user in group : registered users per default
$numgroup ='2';// choose Group number
$query = "insert into ".$prefix."_groups_users_link (groupid, uid) VALUES('".$numgroup."', '".$uid."')";
$result= mysql_query($query);

if (mysql_error()){
echo "Error in database : ".mysql_error();
echo "
UIDPseudo


Importation stoppee.

";
fclose($fp);
exit();
}else{
echo " ".$uid." ".$uname." ";
}
}

echo "
Import finished successfully.";// That's ok !

fclose($fp);
?>


I used this. It succesfully entered the unames BUT without the emails and without the regdate, and without the name. What did i did wrong?

Login

Who's Online

205 user(s) are online (79 user(s) are browsing Support Forums)


Members: 0


Guests: 205


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits