English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Thanks in advance. I am facing one problem. I have two tables A and B(assume). I want to copy A records to B daily and also automatically. How do program for thiss?? any one help me out of this problem???

2007-06-27 19:32:55 · 3 answers · asked by alamelu_dilli 2 in Computers & Internet Programming & Design

3 answers

You need to investigate what scheduling programs are available on you server.
You will then need to write a CGI script.

The only other way is to have a date file. This will hold the date of the last copy. If the date is not today then do the copy. This wants to be in the home page. So the first time anyone opens the home page then the copy will be done. Equally there may be times when the copy is not done for a few days. But because no one has visited the site this probably does not matter. The tables also need to be small.

2007-06-27 20:02:17 · answer #1 · answered by AnalProgrammer 7 · 0 0

If you have access to the mysql client application on the machine, you don't need CGI for this (ie, PHP).

All you need is mysql and a scheduler. The MySQL syntax you need is INSERT INTO

:

INSERT INTO B (id)
SELECT id
FROM A WHERE UNIX_TIMESTAMP(NOW())-A.created_timestamp<(24*60*60)

This simple example will transfer all id's from table A to table B, if created_timestamp is less than 24h old.

Now, you want to execute this command on a daily basis. You can either

... create a sql textfile for this which contains the above statement (for example, daily_sql.txt), and execute sth. like the following command on a daily basis:

/path/to/mysqlclient/mysql -u username -p password < /your_path/daily_sql.txt

... or use the -e option for the mysql client:

/path/to/mysqlclient/mysql -e "INSERT INTO B (id) SELECT id FROM A WHERE UNIX_TIMESTAMP(NOW())-A.created_timestamp<(24*60*60) " -u username -p password

To execute this daily, you need a crontab entry (unix based system) or a scheduled task (windows). Keep in mind to replace "username", "password", "path/to/mysqlclient/" accordingly.

(If you have to use PHP CGI due to your provider's limitations, then a way might be to set up a PHP script with the same INSERT INTO table syntax and request it once a day via http).

Read:
http://en.wikipedia.org/wiki/Crontab
http://www.iopus.com/guides/winscheduler.htm

2007-06-29 06:28:21 · answer #2 · answered by pontello 2 · 0 0

You need to write queries to select row from table a and insert a new row with values obtained in table b
If you nee expert help check http://getafreelnacer.com/

2007-06-28 03:58:33 · answer #3 · answered by easymf co in 3 · 0 1

fedest.com, questions and answers