Jump to content

Output to log file


wiggst3r

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/141442-output-to-log-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.