How can a PHP script be used to export a MySQL database without using phpMyAdmin?

To export a MySQL database using a PHP script without using phpMyAdmin, you can use the `mysqldump` command line tool within the PHP script. This tool allows you to create a backup of the database in SQL format. By executing the `mysqldump` command through PHP's `exec()` function, you can export the database directly from your script.

<?php

// Set database credentials
$host = 'localhost';
$user = 'username';
$password = 'password';
$database = 'database_name';

// Set the path where the backup file will be saved
$backupFile = 'backup.sql';

// Execute mysqldump command to export the database
exec("mysqldump --user={$user} --password={$password} --host={$host} {$database} > {$backupFile}");

echo 'Database exported successfully!';
?>