Home >Database >Mysql Tutorial >How to Automate MySQL *.sql File Execution in PHP for Website Generation, Considering Zend Framework Compatibility?
Run MySQL *.sql file in PHP
Question:
How to execute from PHP MySQL *.sql file, automate the website generation process, taking into account the availability of Zend Framework?
Answer:
Use shell_exec() method.
$command = 'mysql' . ' --host=' . $vals['db_host'] . ' --user=' . $vals['db_user'] . ' --password=' . $vals['db_pass'] . ' --database=' . $vals['db_name'] . ' --option=option_value' . ' --execute="SOURCE ' . $script_path ; $output1 = shell_exec($command . '/site_db.sql"'); $output2 = shell_exec($command . '/site_structure.sql"');
Additional notes:
The difference between shell_exec() and exec():
This issue was not clearly explained initially, but you can refer to the related discussion.
The above is the detailed content of How to Automate MySQL *.sql File Execution in PHP for Website Generation, Considering Zend Framework Compatibility?. For more information, please follow other related articles on the PHP Chinese website!