wiggst3r Posted January 19, 2009 Share Posted January 19, 2009 Hi I have a script that outputs a count to screen/terminal with a count of rows inserted into a db. As the db tble to be imported is approx 400,000 records, i want to output the count and details to a log file. So If the browser crashes or SSH connection times out. I know what row the import got upto. My script is as follows: <?php require(dirname(__FILE__) . "/../config.php"); require(dirname(__FILE__) . "/../models/index_model.php"); class MergeModel extends IndexModel { function MergeModel() { $db = $this->connect_to_db(); //get all voda entries $vodaphone_entries = $db->get_all('entries_vodaphone', false); $count = 0; while($one_voda_entry = $db->db_fetch($vodaphone_entries)) { echo "\n$count"; $count++; //we now have 1 vodafone entry - lets unset the id $old_entry_id = $one_voda_entry['id']; unset($one_voda_entry['id']); //insert into normal entries table $new_entry_id = $db->insert_row('entries', $one_voda_entry); echo "entry $new_entry_id - "; //we now have a new entry. lets get the friends for this person and insert them using the new id $persons_friends = $db->get_rows_using_columns('added_friends_vodaphone', $constraints=array('entry_id' => $old_entry_id)); foreach($persons_friends as $one_friend) { //we now have 1 friend of this person. Lets insert them into the new DB unset($one_friend['id']); //set the entry id to be that of the new entry $one_friend['entry_id'] = $new_entry_id; echo "friend - "; $db->insert_row('added_friends', $one_friend); } $persons_children = $db->get_rows_using_columns('children_vodaphone', $constraints=array('entry_id' => $old_entry_id)); foreach($persons_children as $one_child) { //we now have 1 friend of this person. Lets insert them into the new DB unset($one_child['id']); echo "kid - "; //set entry id to be that of the new entry $one_child['entry_id'] = $new_entry_id; $db->insert_row('children', $one_child); } } } } new MergeModel; ?> It outputs the following to screen: 0entry 826013 - 1entry 826014 - 2entry 826015 - 3entry 826016 - friend - friend - friend - friend - friend - kid - kid - kid - So I want all that to go into the log file. Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 Simply send the output to a file when the script is called. eg; $ php yourscript.php > out.log Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.