How can a SQL dump file be created from a MySQL database using PHP?

To create a SQL dump file from a MySQL database using PHP, you can use the `mysqldump` command line tool to export the database structure and data into a file. You can execute this command using PHP's `exec()` function.

<?php
// Set the database credentials
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database_name';

// Set the path for the SQL dump file
$dumpFile = 'dump.sql';

// Execute mysqldump command to create the SQL dump file
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$db} > {$dumpFile}");

echo "SQL dump file created successfully!";
?>