Create .SQL File of MySQL table using Query in PHP

Want to get backup of your table without login on PHPMyAdmin? Yes you can do this in PHP just write 4 to 5 lines code.Create page (mysql_backup.php) on your website and add below code.

 

define('DS', '\');

define('ROOT_PATH', 'YOUR_SERVER_PATH');

$table_name = "categories";

$backup_file = ROOT_PATH. DS ."categories.sql";

$sql = "SELECT * INTO OUTFILE '".$backup_file."' FROM ". $table_name;

mysqli_query($sql);

 

Run mysql_backup.php and database tables backup file save on your server.

 

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.