How can I create a backup of a table in a SQL database using PHP code?

To create a backup of a table in a SQL database using PHP, you can use the `mysqldump` command to export the table structure and data to a SQL file. You can then save this SQL file as a backup for future use. This can be achieved by executing the `mysqldump` command through PHP's `exec()` function.

<?php
// Set the database connection details
$host = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database_name';
$table = 'table_name';

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

// Create the mysqldump command
$command = "mysqldump --host=$host --user=$username --password=$password $database $table > $backup_file";

// Execute the command to create the backup
exec($command);

echo "Backup of table $table created successfully!";
?>