Log in

View Full Version : Mysql work...


nsglazer
01-22-2002, 11:35 PM
I have a old registration database from my site that has the following info:

username
password (tiny text)
first_name
last_name
email_address

Is it possible to migrate this over to vbulletin? I don't know how comfortable I feel playing with databases myself. Are there any developers that can do this work for me? If so, please contact me off list with a quote.

Neil

Admin
01-23-2002, 07:37 AM
What's the name of your current table? And are the passwords encrypted in some how, or are they kept as plain text (i.e if your password is "blabla" it would say "blabla" in the password field)?

Oh and just so you know vBulletin doesn't have fields for first/last name, so they will need to be deleted.

nsglazer
01-23-2002, 12:53 PM
This info is in a separate database (called studentpilot). The table is called "users"

The relevant fields are therefore:

username
password
email_address

The password it not encrypted.. So if a password was "car" the database shows it as "car".

I also have a field for date of birth. It's in the following format:

1976-02-29
YEAR-MONTH-DAY

Neil

Scott MacVicar
01-23-2002, 01:53 PM
I'll do something just now, unless chen can beat me :P

whats your main vBulletin database called?

Scott MacVicar
01-23-2002, 02:21 PM
put this code into a text edit and save it as a php file, ie file.php
upload to your vBulletin forums directory and then go run it in your browser, it will import from this old database you've described to the new vBulletin one, I presume your using 2.2.0 or above.

<?
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT * FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob])");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ('$userid','','','','')");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>

nsglazer
01-23-2002, 02:44 PM
Thanks for the help.. That was quick... I had to make a slight change to the file (since I had other fields in the database). I changed it to:

<?
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT username, password, email_address, dob FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday) VALUES ('".addslashes(htmlspecialchars($username))."','".addslashes(md5($password))."','".addslashes(htmlspecialchars($email))."', $users[birthday])");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ($userid)");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>

Anyway, I get the following error:

Database error in vBulletin 2.2.1:

Invalid SQL: INSERT INTO user (username, password, email, birthday) VALUES ('','d41d8cd98f00b204e9800998ecf8427e','', )
mysql error:

mysql error number: 0

Date: Wednesday 23rd of January 2002 11:46:22 AM
Script: http://www.studentpilot.com/interact/forum/interact/forum/file.php
Referer:

nsglazer
01-23-2002, 02:55 PM
By the way -- there are currently 25 subscribed members in the new vbulletin forum. Would this impact the migration in any way?

Scott MacVicar
01-23-2002, 03:13 PM
I've adjusted the code at the top could you put that all info file.php again and re-upload.

It will have no effect on new users.

nsglazer
01-23-2002, 03:18 PM
Now I get this error:

Database error in vBulletin 2.2.1:

Invalid SQL: INSERT INTO userfield VALUES (26)
mysql error:

mysql error number: 0

Date: Wednesday 23rd of January 2002 12:18:55 PM
Script: http://www.studentpilot.com/interact/forum/interact/forum/file.php
Referer:


FYI: There were 25 entries before this one... It made a 26th entry in the database that looks correct to me.

Sparkz
01-23-2002, 03:21 PM
Originally posted by nsglazer
By the way -- there are currently 25 subscribed members in the new vbulletin forum. Would this impact the migration in any way?

It shouldn't affect the migration, as each new user is assigned a new and unique userid.

Looking at your code, I think it should be changed to this (not tested):


<?php
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT username, password, email_address, dob FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob])");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ($userid)");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>


I guess someone was a bit to fast on the trigger while trying to get ahead of Chen to the solution ;)

EDIT: But then again, a certain someone fixed his bugs faster than me :)

Scott MacVicar
01-23-2002, 03:24 PM
edited my first post again, and i tested it this time to check for errors, :)

it works sorry about those first errors, and the person with id 26 will be duplicated.

nsglazer
01-23-2002, 03:30 PM
I have one other question... How would I modify this code one last time to give a value of "2" to the usergroupid fields-- This is so I don't have to manually give everybody permission later.. I think thats the right thing that needs changing? Is there anything else in the other fields that needs to be set in advance? I want to make sure I get this right now... I am migrating 7,000+ records.

Thanks
Neil

Scott MacVicar
01-23-2002, 03:35 PM
$DB_site->query("INSERT INTO user (username, password, email, birthday) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob])");

becomes

$DB_site->query("INSERT INTO user (username, password, email, birthday,usergroupid) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob]), '2'");

nsglazer
01-23-2002, 03:42 PM
I don't seem to be having much luck with this. Now I get the following error:

Database error in vBulletin 2.2.1:

Invalid SQL: INSERT INTO user (username, password, email, birthday,usergroupid) VALUES ('mike','efe6398127928f1b2e9ef3207fb82663','mike@n o.com', 1976-02-29), '2'
mysql error:

mysql error number: 0

Date: Wednesday 23rd of January 2002 12:42:40 PM
Script: http://www.studentpilot.com/interact/forum/interact/forum/file.php
Referer:

Just to double check, this is exactly what the file looks like:


<?
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT username, password, email_address, dob FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday,usergroupid) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob]), '2'");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ('$userid','','','','')");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>

Scott MacVicar
01-23-2002, 03:45 PM
I don't seem to be having a good coding day lol

try this


<?
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT username, password, email_address, dob FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday,usergroupid) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob], '2')");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ('$userid','','','','')");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>

nsglazer
01-23-2002, 03:48 PM
Hmm... Well, that fixed the last problem... But now I have a new problem. Looking at the mysql database, one record is added with that code... Then it gets this message:

Database error in vBulletin 2.2.1:

Invalid SQL: INSERT INTO userfield VALUES ('31','','','','')
mysql error:

mysql error number: 0

Date: Wednesday 23rd of January 2002 12:48:26 PM
Script: http://www.studentpilot.com/interact/forum/interact/forum/file.php
Referer:



By the way, thanks for all of your help with this. I really appreciate it. Without your help I would be totally lost.

Neil

Scott MacVicar
01-23-2002, 03:51 PM
how many custom fields have you created?

nsglazer
01-23-2002, 03:54 PM
There are five Custom Profile Fields:

Title Required Hidden Editable Maxlength Size Modify
Total Time No No Yes 250 25 [edit] [remove]
Ratings No No Yes 250 25 [edit] [remove]
I Fly No No Yes 250 25 [edit] [remove]
Location No No Yes 250 25 [edit] [remove]
Occupation No No Yes 250 25 [edit] [remove

Neil

Scott MacVicar
01-23-2002, 03:54 PM
I checked your register page, you have 5 custom fields according to that.
Use this version then
<?
require("./global.php");
if(empty($start)) {
$start = 0;
}
$query = $DB_site->query("SELECT username, password, email_address, dob FROM studentpilot.users LIMIT $start, 100");
while($users = $DB_site->fetch_array($query)) {
$finished = 1;
$DB_site->query("INSERT INTO user (username, password, email, birthday,usergroupid) VALUES ('".addslashes(htmlspecialchars($users[username]))."','".addslashes(md5($users[password]))."','".addslashes(htmlspecialchars($users[email_address]))."', $users[dob], '2')");
$userid = $DB_site->insert_id();
$DB_site->query("INSERT INTO userfield VALUES ('$userid','','','','','')");
}
if($finished) {
echo "<p><script language=\"javascript\">window.location=\"$PHP_SELF?start=".($start+100)."#end\";</script><a name=\"end\"></a><a href=\"$PHP_SELF?start=".($start+100)."#end\"><b>Continue with next</b></a></p>\n";
}
else {
echo "<p>Import complete</p>";
}
?>

nsglazer
01-23-2002, 04:10 PM
IT worked!!! Imported 7,024 new users :-)

You saved me a ton of time and a headache -- thanks for all the help!

NEil

Scott MacVicar
01-23-2002, 04:20 PM
I'm suprised it took me that long to get it right, I'm definately having a bad coding day, I've done far too many stupid mistakes.

Sparkz
01-24-2002, 07:10 AM
Originally posted by PPN
I'm suprised it took me that long to get it right, I'm definately having a bad coding day, I've done far too many stupid mistakes.

*cough* maybe you should take that as a hint ;)

TheComputerGuy
02-12-2002, 08:56 AM
Does this still work...

I want to import my old VB 2.03 db..can it be done with this script? I want them to merge not erase.

Scott MacVicar
02-12-2002, 03:49 PM
this was for a custom script that nsglazer was running not another copy of vBulletin, it was also going to an empty database not one with data already in it.