2

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.

Oscar Foley
  • 6,817
  • 8
  • 57
  • 90
mulekula
  • 29
  • 1
  • 6
  • 5
    You can use a cron (linux) or scheduled task (windows) to execute your script every 10 minutes. More info setting those up in this question: http://stackoverflow.com/questions/120228/php-running-scheduled-jobs-cron-jobs – Mike B Jun 12 '12 at 16:46
  • I recommend a very slow (drinking bird)[http://en.wikipedia.org/wiki/Drinking_bird] tapping the enter key on a dedicated machine, or a JavaScript `setInterval`.. just leave the browser open all the time – Rudu Jun 12 '12 at 16:52
  • how can i do this without cron? – mulekula Jun 12 '12 at 16:53
  • mulekula: I have edited your post to fix a couple of English syntax errors and make it a little bit clearer. No need to apologize about your English level.. my Russian level is worst for sure :) – Oscar Foley Jun 12 '12 at 16:55
  • ok i use Debian. so i create a cron task and then i need to create a php file thet must copy a date to a new data base? – mulekula Jun 12 '12 at 17:02
  • @mulekula Why are you asking us? You asked how to execute a function every 10 minutes.. whatever you do with that script/function is up to you. – Mike B Jun 12 '12 at 17:51

2 Answers2

2

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
Oscar Foley
  • 6,817
  • 8
  • 57
  • 90
1

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

Community
  • 1
  • 1
Sibiraj PR
  • 1,481
  • 1
  • 10
  • 25