I have a question regarding php and mysql. What I have is a php backup script that dumps the data in the form of INSERT INTO ...
I am using innodb and foreign key constraints. When the user downloads the sql file for the db, the tables are not in the order that they need to be for the restore. The restores will always fail because of the foreign key constraints.
I am developing on a windows machine and will host in a UNIX environment. In the mean time, can someone tell me how I can inplement this code using php to turn off the constraints?
Expand|Select|Wrap|Line Numbers
- (
- echo "SET AUTOCOMMIT=0;"
- echo "SET FOREIGN_KEY_CHECKS=0;"
- cat databasedump.sql
- echo "SET FOREIGN_KEY_CHECKS=1;"
- echo "COMMIT;"
- echo "SET AUTOCOMMIT=1;"
- ) | mysql --user=username --password=password database
Heck, I may as well ask as long as I am here.. Is it ok to use php's exec func for the restore or is there a better way?
Thank you,
Frank