Page 1 of 1

script to trans. data one db to another db

Posted: Wed Jan 07, 2004 4:31 pm
by lparnau
I have installed a new safelist script on my domain. I have placed the tables for both in the same db. Now I need to transfer the databases.
I have written a short script for this but seems something is wrong? Can someone take a quick look to see what I have done wrong. :oops:

Thank you for your help in advance.

Old table: safe_members
New table: SP_members
Both tables in same database

--------------- Script ---------------
<?php

$db = mysql_connect("localhost", "xxxxxxxxx", "xxxxxxxxx");

mysql_select_db("xxxxxxxxx",$db);

$result = mysql_query("SELECT * FROM safe_members",$db);

while ($myrow = mysql_fetch_array($result)) {

$id = $myrow["userid"];

$Fullname = $myrow["fullname"];

$C_email = $myrow["contact"];

$S_email = $myrow["subscribe"];

$Type = $myrow["type"];

$Joindate = $myrow["joindate"];

$Points = $myrow["points"];

$Active = $myrow["VERIFIED"];

if ($Type == "FREE") {$Type == "0"};
elseif ($Type == "PRO") {Type == "1"};
elseif ($Type == "PLATINUM") {Type == "3"};

if ($Active == "VERIFIED") {$Active == "ON"} else {$Active == ""};


$sql = "INSERT INTO SP_members (username,fullname,contact_email,list_email,membership,date_joined,credits,activation) VALUES ('$id','$Fullname','$C_email','$S_email','$Type','$Joindate','$Points','$Active)";

}
?>

Posted: Wed Jan 07, 2004 8:01 pm
by Weirdan
why not just:

Code: Select all

insert into SP_members select userid as username, fullname as fullname, contact as contact_email, subscribe as list_email, case type when 'FREE' then 0 when 'PRO' then 1 when 'PLATINUM' then 3 end as membership, join_date as date_joined, points as credits, if(VERIFIED=='VERIFIED','ON','') as activation from safe_members;
?

[edit]
Indeed query was wrong. Edited.
[/edit]

Posted: Wed Jan 07, 2004 8:07 pm
by Pyrite
Wow. Smooth Weirdan :P