What is the best practice for importing an SQL file into a database using PHP?

When importing an SQL file into a database using PHP, the best practice is to use the `exec()` function to execute the MySQL command line tool. This allows you to run the SQL file as a command directly in the terminal. By using this method, you can ensure that the SQL file is imported into the database without any issues.

<?php

$database = 'your_database_name';
$username = 'your_username';
$password = 'your_password';
$sqlFile = 'path/to/your/sql/file.sql';

// Execute MySQL command to import SQL file
exec("mysql -u $username -p$password $database < $sqlFile");

echo "SQL file imported successfully";
?>