Backup Data from Database using SQL Command through PHP

0
93

Hello everyone! Today, I’m gonna teach you on one way of backing up a data from database using sql command through PHP.

There are three (3) ways of taking backup of your MySQL databases which are: using SQL Command, using MySQL Binary mysqldump, these two are through PHP, and last is using phpMyAdmin user interface.

But for now, we will use the first way. So let’s start.

First, execute a SQL SELECT command to take backup of any table and to complete database dump you must need to write separate query for separate table and each table will be stored into separate text file.

And the codes for that are as follows:

  1. <?php<?php include 'conn.php'; $table_name = "files"; $backup_file = 'db_backup/files.sql'; $backup_db = $conn->query("SELECT * INTO OUTFILE '$backup_file' FROM $table_name"); if (!$backup_db) { die('Could not take data backup: ' . $conn->error); } else { echo 'Backed up data successfully!'; }?>

And thats all the codes needed for backing up of data in using the sql command through php. That’s all.

If you have questions regarding these tutorial entitled as “Backup Data from Database using SQL Command through PHP” feel free to ask us by commenting below or visit on our contact page. Thank you.

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here