I am a beginner with PHP. 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 i开发者_StackOverflow社区s the best way? Do I have to create table and insert all data?
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
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.
How to Backup and Restore
Mysql Import
Intro to Cron
精彩评论