Moin Moin zusammen
ich habe ein Script:
welches Tabellen aus einer Datenbank in die andere Datenbank kopieren soll.
Wenn ich nun dieses script aufrufe erhalte ich folgendes:
Die Warning´s sind nicht so schlimm, aber der ERROR stört
DB Error: constraint violation
ich habe schon über all nachgeschaut - konnte aber keine Hilfe für mein Problem finden
vielleicht kennt von euch einer eine Lösung.....
gruss
ich habe ein Script:
PHP-Code:
<pre>
<?
// If your reading this your a smart person.
// It is highly RECOMMENDED you backup your databases.
// This script will clear your Land Down Under database and import user info from phpNuke
// It also imports smilies and the forums if you used the phpBB port
//
// This was tested on phpNuke 6.9 with the phpBB nuke port
// The database type I use is mySQL. If you have some other type like
// postGres then this script MIGHT not work!!!!
//
// Credits goto Xalon for giving me a script he had for importing the data for phpBB forums to LDU
// Rogue (me) modified this script for phpNuke conversion.
// I plan on adding all the other features of phpNuke to this like News and such.
//
// Any problems with this script is unsupported but you can post in the LDU forums:
// [url]http://ldu.neocrome.net/forums.php[/url] under the topic "Plugins, Modifications, and Add-Ons"
//
require_once 'PEAR.php';
require_once 'DB.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
set_time_limit (216000); // 1h ;)
// Configuration - Please edit for your setup
$dbUserName = "***"; // your phpNuke Database Username
$dbUserPass = "****"; // your phpNuke Database Password
$nuke_db = "*****"; // Your phpNuke Database name default is nuke
$NukeExt = "phpbb"; // You table extension for phpNuke tables. The default is set.
$dbUserName_ldu = "****"; // The USER Name for connecting to the LDU database
$dbUserPass_ldu = "****"; // The Password for connecting to the LDU database
$lduDatabase_Name = "********"; // What is the name of the LDU database
$default_skin = "pandora"; // Default LDU skin
$default_lang = "uk"; // Default LDU Lang
$ldu_smilies_dir = "system/smilies/"; // LDU smilies directory
$regdate = time ();
$db_ldu = "mysql://$dbUserName_ldu:$dbUserPass_ldu@localhost/$lduDatabase_Name"; // DO NOT CHANGE
$db_phpbb = "mysql://$dbUserName:$dbUserPass@localhost/$nuke_db"; //DO NOT CHANGE
$db1 = DB::connect($db_phpbb); // DO NOT CHANGE
$db2 = DB::connect($db_ldu); // DO NOT CHANGE
// WARNING DO NOT EDIT BELOW THIS LINE
if (DB::isError($db1))
{
die ("DB1 : ".$db1->getMessage());
}
if (DB::isError($db2))
{
die ("DB2 : ".$db2->getMessage());
}
echo "[ ok] Databases ok, starting import\n";
#
# users
#
echo "Preparing nukes_user table for export\n";
$db = mysql_connect("localhost", $dbUserName, $dbUserPass);
mysql_select_db($nuke_db,$db);
// Create temp column in phpNuke users table for microtime conversion
mysql_query("ALTER TABLE ".$NukeExt."_users ADD COLUMN tempTime int(11)",$db);
// Pull date change it to microtime and put back into column named
$result = mysql_query("SELECT * FROM ".$NukeExt."_users",$db);
if ($myrow = mysql_fetch_array($result)) {
do {
// Convert date to microtime
// tempRow is needed to keep user id's consistant when running the UPDATE command
$date=$myrow["user_regdate"];
$tempRow=$myrow["user_id"];
$dateArray=explode(" ",str_replace(",","",$date));
$monthArray=array("1"=>"Jan","2"=>"Feb","3"=>"Mar","4"=>"Apr",
"5"=>"May","6"=>"Jun","7"=>"Jul","8"=>"Aug",
"9"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec");
foreach($monthArray as $key=>$value) {
if($value==$dateArray[0]) {
$dateArray[0]=$key;
}
}
$timeStamp=mktime(0,0,0,$dateArray[0],$dateArray[1],$dateArray[2]);
// show the data
printf("%s %s %s \n", $myrow["user_id"], $myrow["user_regdate"], $timeStamp);
// send converted data back
mysql_query("UPDATE ".$NukeExt."_users SET tempTime = '$timeStamp' WHERE user_id = '$tempRow'");
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
echo "Sorry, no records were found!";
}
echo "Starting Import of Users \n";
$db2->query("DELETE from ldu_users");
$prep = $db2->prepare
(
"INSERT INTO ldu_users (
user_id, user_active, user_banned, user_name,
user_password, user_level, user_country, user_text,
user_avatar, user_extra1, user_extra2, user_extra3,
user_extra4, user_extra5, user_occupation, user_location,
user_birthdate, user_gender, user_irc, user_email,
user_regdate, user_skin, user_lang
) VALUES
(
?,?,0,?,
?,1,'','',
'','','','',
'','',?,?,
0,'','',?,
?, '$default_skin', '$default_lang')"
);
/* Change table nuke_users to what you have for users table in phpNuke
*/
$data = $db1->getAll
(
"SELECT
user_id, user_active, username,
user_password,
user_occ, user_from, user_email,
tempTime
FROM ".$NukeExt."_users"
);
$db2->executeMultiple($prep, $data );
echo "[ ok] ".count($data)." users imported.\n";
echo "se kr dela \n";
// for later user we get user ids as a record
$users = $db1->getAssoc("SELECT user_id, username FROM ".$NukeExt."_users");
echo "Now for the forum categories \n";
#
# Categories
#
$db2->query("DELETE from ldu_forum_sections");
$sections = $db1->getAssoc("SELECT cat_id, cat_title FROM ".$NukeExt."_categories");
$data = $db1->getAll("SELECT forum_id, forum_name, cat_id, forum_desc, forum_topics, forum_posts FROM ".$NukeExt."_forums");
// change category field from id to section name
for ($i=0; $i< count($data);$i++)
{
$category_id = $data[$i][2];
$data[$i][2] = $sections[$category_id];
}
$prep = $db2->prepare
(
"INSERT INTO ldu_forum_sections ( fs_id, fs_title, fs_category, fs_desc, fs_icon, fs_topiccount, fs_postcount ) VALUES
(?,?,?,?,0,?,?)"
);
$db2->executeMultiple($prep, $data );
echo "[ ok] ".count($data)." forum categories imported\n";
#
# Topics
#
$db2->query("DELETE from ldu_forum_topics");
$prep = $db2->prepare
(
"INSERT INTO ldu_forum_topics (
ft_id, ft_title,ft_sectionid, ft_firstposterid,
ft_firstpostername, ft_postcount, ft_viewcount, ft_updated,
ft_lastposterid, ft_lastpostername )
VALUES (?,?,?,?,?,?,?,?,?,?)"
);
$data = $db1->getAll
(
"SELECT
topic_id, topic_title, forum_id, topic_poster,
topic_poster, topic_replies, topic_views, topic_time
FROM ".$NukeExt."_topics"
);
for ($i=0; $i< count($data);$i++)
{
$data[$i][4] = $users[$data[$i][4]]; // replace id with username
$data[$i][8] = -1; // can't find out
$data[$i][9] = ''; // can't find out
}
$db2->executeMultiple($prep, $data );
echo "[ ok] ".count($data)." topics imported\n";
#
# Posts
#
$db2->query("DELETE from ldu_forum_posts");
$prep = $db2->prepare
(
"INSERT INTO ldu_forum_posts
(
fp_id, fp_topicid, fp_sectionid, fp_posterid,
fp_postername, fp_updated, fp_posterip, fp_text
)
VALUES (?,?,?,?,?,?,?,?)"
);
$data = $db1->getAll
(
"SELECT
post_id, topic_id,forum_id, poster_id,
poster_id, post_time, poster_ip
FROM ".$NukeExt."_posts"
);
$data_text = $db1->getAssoc
(
"SELECT
post_id, post_text
FROM ".$NukeExt."_posts_text"
);
for ($i=0; $i< count($data);$i++)
{
$data[$i][4] = $users[$data[$i][4]];
$data[$i][7] = $data_text[$data[$i][0]];
}
echo "[info] starting posts import, this might take a while ...\n";
$db2->executeMultiple($prep, $data );
echo "[ ok] ".count($data)." posts imported\n";
echo "[done] Don't forget to put your smilies in the smiley directory!\n";
?>
</pre>
Wenn ich nun dieses script aufrufe erhalte ich folgendes:
PHP-Code:
[ ok] Databases ok, starting import
Preparing nukes_user table for export
Warning: mktime() [function.mktime]: Windows does not support negative values for this function in C:\apachefriends\xampp\htdocs\LDU800-WE\dbimport.php on line 93
-1 1022507715 -1
Warning: mktime() [function.mktime]: Windows does not support negative values for this function in C:\apachefriends\xampp\htdocs\LDU800-WE\dbimport.php on line 93
2 1022507715 -1
Warning: mktime() [function.mktime]: Windows does not support negative values for this function in C:\apachefriends\xampp\htdocs\LDU800-WE\dbimport.php on line 93
3 1120412490 -1
Starting Import of Users
[ ok] 3 users imported.
se kr dela
Now for the forum categories
[ ok] 15 forum categories imported
DB Error: constraint violation
DB Error: constraint violation
ich habe schon über all nachgeschaut - konnte aber keine Hilfe für mein Problem finden
vielleicht kennt von euch einer eine Lösung.....
gruss
Kommentar