SQL表复制脚本

时间:2012-08-30 23:44:28

标签: php mysql

我有一个网站http://www.league.vivahosting.co.uk,它使用Joomla作为主要cms,使用Dragonflycms作为联盟组件模块。

现在我想要实现的是从jos_users表复制用户名和电子邮件并将其插入cmsdf_users表的脚本,现在每个表中的行如下所示

jos_users - username, email
cmsdf_users - username, user-email

现在我想对密码做同样的事情,但是joomal的加密是hash:我相信salted并且Dragonflycms是md5所以我正在考虑使用joomla提供的自定义字段来解决方法,使用加密的普通txt密码在从db到db的传输过程中。

现在,自定义字段未保存在位于letnp_user的jos_users表中,我认为该表位于user_id之间。

以下是我到目前为止的内容

<?php

// Set the connection information
print $con = mysql_connect("localhost", "DBName", "Pass");

// Select the original database containing old records
print mysql_select_db("DBName", $con);

// Check the connection
if (!$con)
{
print die('Could not connect: ' . mysql_error());
}

// Select the records from the database
print $query = "SELECT * FROM letnp_users" or die(mysql_error());

// Run the query
print $result = mysql_query($query);

// Now select the new database
# mysql_select_db("cmsdf_users", $con);

// Loop through each row from the old database
while ($row = mysql_fetch_assoc($result))
{
     // Set each column to a variable
    $username = $row['username'];
    echo  $username;    
    $email = $row['email'];
    echo $email;
     // You could also reset defaults or check for NULL columns
     // Here's an example for permissions:
     if ($row['permissions'] == 0)
     {
          $permissions = 1;
     }
     else if ($row['permissions'] > 3)
     {
          $permissions = $row['permissions'] + 1;
     }
     else
     {
          $permissions = $row['permissions'];
     }
     $date = $row['date'];

     // Set up the INSERT query
     $insert = "INSERT INTO cmsdf_users (username, user_email) VALUES ('$username', '$user_email')";


     // Run the INSERT query
    $insert = mysql_query
    ("
    INSERT INTO cmsdf_users(username,user_email)
    VALUES (NULL,'".$user."','".$user_email."')
    "); 


     // Check to make sure this particular INSERT worked
     if (!mysql_insert_id())
     {
          echo "ERROR: there was a problem inserting data.";
     }
}

// Close the connection
print mysql_close($con);

?>

但似乎不起作用它会产生以下错误

Resource id #11SELECT * FROM letnp_usersResource id #2Cprl.Rstadmin@vivahosting.co.ukERROR: there was a problem inserting data.1

0 个答案:

没有答案