Gekk0 Posted April 15, 2010 Share Posted April 15, 2010 Hi, i need to backup several tables from my MySql database using php. I just need some quick and easy method, nothing fancy, to backup tables and restore tables. I searched around and found a tutorial on the subject here http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx but i can seem to get the script to work, i'm using this: <?php $tableName = 'bookingBOOKINGS'; $backupFile = $_SERVER['DOCUMENT_ROOT'] . '/bookingBOOKINGS.sql'; $query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"; $result = mysql_query($query); ?> I added the $_SERVER variable into $backupFile think it might help - but no cigar. I'm not getting any errors, either the file isnt being generated or i can't find it ( :-\ , doubt that though). Maybe I've been tricked by such a simple few lines of script to thinking i'd found a easy solution! I'd be happy to hear alternatives, i cant use exec() function, which another tutorial suggested, cause "its disabled for security reasons". Cheers Link to comment https://forums.phpfreaks.com/topic/198641-backingup-mysql-with-php/ Share on other sites More sharing options...
andrewgauger Posted April 15, 2010 Share Posted April 15, 2010 I'd suspect that the scope of your MySQL database is not the same as your php scripts. If you have phpMyadmin try your query in there first. You will get your errors. Also you can try: echo mysql_error(); after $result=mysql_query($query). I am pretty sure that the problem is you are tying to append the DOCUMENT_ROOT directive to your filename. MySQL probably doesn't have access to that directory. You also won't have access to files that MySQL generates. The easiest way maybe found on the link you provided: To backup your MySQL database using phpMyAdmin click on the "export" link on phpMyAdmin main page. Choose the database you wish to backup, check the appropriate SQL options and enter the name for the backup file. Link to comment https://forums.phpfreaks.com/topic/198641-backingup-mysql-with-php/#findComment-1042483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.