mulekula
mulekula

Reputation: 29

function that updates the database every 10 min

I have two databases. Below is the code that I am using to get information from the first database.

$myrow = mysql_query("SELECT SUM(uploaded) FROM peers",$db);
$sum = mysql_fetch_array($myrow);
$c = $sum[0] / 1000000;
$d = $c / 1000000;
$l = round($d,3);


echo "<p>UP: $l TB</p>";


$myrow1 = mysql_query("SELECT SUM(downloaded) FROM peers",$db);
$sum1 = mysql_fetch_array($myrow1);
$a = $sum1[0] / 1000000;
$b = $a / 1000000;
$k = round($b,3);

echo "<p>DW: $k TB</p>";

I need to add this information to my second database and update it every 10 min with new fresh information from first database. I am using phpmyadmin.

Upvotes: 2

Views: 1783

Answers (2)

Oscar Foley
Oscar Foley

Reputation: 7025

Your question is very generic so I will try to answer for all scenario You shoud create a process that run every 10 minutes (cron if you use Linux, scheduled task if you use windows)

If you use Linux you can

  • If you really want to use PHP, create a PHP script and call it using php command line or (much worst) create a php page that do what you want and have CRON to call it every 10 mins using LYNX browser.
  • Create a program in c/python/etc. that connects to first DB, query info, and writes to second.
  • Create a bash script that use mysql commandline to connect to DBs and do the same. (This has the advantage of not having to program)

If you use Windows you can:

  • Create a scheduled task in C# or vb.net or similar
  • Create a scheduled task using powershell

Upvotes: 2

Sibiraj PR
Sibiraj PR

Reputation: 1481

Use cron jobs for updating your information in DB.

cron jobs or PHP scheduler

http://net.tutsplus.com/tutorials/other/scheduling-tasks-with-cron-jobs

Upvotes: 1

Related Questions