ich benutze folgendes klein script um daten in eine tabellen zu importieren. leider sind es c.a 4,5 millionen datensätze und mein server läuft in den timeout, kann mir jemand einen tipp geben wie man das evtl. umgehen kann ???
PHP-Code:
<?php
$link = mysql_connect('server', 'db', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br>';
mysql_select_db("db", $link);
// Get the records from transition table
$schooldata = mysql_query("SELECT * FROM private_schools", $link);
//set the counter for the last query
$i=0;
//Add record jos_sobi2_item table
while ($row = mysql_fetch_assoc($schooldata)) {
//insert a record into the item table
$results = mysql_query("INSERT INTO jos_sobi2_item (title) VALUES ('".$row['school_name']."')", $link);
//get the last item itemid
$itemid = mysql_query("SELECT MAX(itemid) FROM jos_sobi2_item", $link);
$row_itemid = mysql_fetch_row($itemid);
//now build a record for the fields data
$result1 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('1', '".$row['address1']."', '".$row_itemid[0]."')");
$result2 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('2', '".$row['zipcode']."', '".$row_itemid[0]."')");
$result3 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('3', '".$row['city']."', '".$row_itemid[0]."')");
$result4 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('4', '".$row['county']."', '".$row_itemid[0]."')");
$result5 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('5', '".$row['state']."', '".$row_itemid[0]."')");
$result6 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('7', '".$row['school_email']."', '".$row_itemid[0]."')");
$result7 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('8', '".$row['school_url']."', '".$row_itemid[0]."')");
$result8 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('9', '".$row['contact_fn']."', '".$row_itemid[0]."')");
$result9 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('10', '".$row['phone']."', '".$row_itemid[0]."')");
$result10 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('11', '".$row['fax']."', '".$row_itemid[0]."')");
$result11 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('14', '".$row['address2']."', '".$row_itemid[0]."')");
$result12 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('15', '".$row['principal_email']."', '".$row_itemid[0]."')");
$result13 = mysql_query("INSERT INTO jos_sobi2_fields_data (fieldid, data_txt, itemid) VALUES ('16', '".$row['contact_ln']."', '".$row_itemid[0]."')");
// update the cat_items_relations table
$result14 = mysql_query("INSERT INTO jos_sobi2_cat_items_relations (catid, itemid, ordering) VALUES ('3', '".$row_itemid[0]."', '".$i."')");
$i++;
//now update so the items are published and data is good
$result15 = mysql_query("UPDATE jos_sobi2_item SET published='1', confirm='0', approved='1', archived='0', publish_up=NOW(), publish_down='3000-12-12 00:00:00', checked_out='0', owner='62', ip='127.0.0.1'");
}
echo "Done!";
mysql_close($link);
?>
Kommentar