tags:

views:

92

answers:

3

Please bear with me(beginner).

I am planning to set up an application where visitors can login and play/mess around with my application.

So I want to refresh my php application once a day with a cron job.

But I never wrote a cron job script before.

I understand that I have to truncate all the tables/data and add the initial data.

With phpmyadmin, I can import data. Is there any way I can import sql file after truncate the tables?

What is the best way?

Do I have to create table and insert all data?

Help and resources will be appreciated.

Thanks in advance.

A: 

if you want to execute an sql file on your database, you don't even need phpmyadmin. if mysql and php are running on the same machine you have mysql tools installed. if you control the data dumping you can use the mysqldump/mysqlimport combo. if not you can generate an sql file and execute it with the "mysql" CLI program.

shell> mysql db_name < script.sql
Ysangkok
A: 

Maybe you do not have access to the mysql command or you can only execute php/cgi scripts with cron (like on most shared hostings).

In that case, you can parse the .sql file in PHP and execute the queries with mysql_query(). There is an example at the bottom of this page.

Klaus