Home >Database >Mysql Tutorial >How to Automate MySQL *.sql File Execution in PHP for Website Generation, Considering Zend Framework Compatibility?

How to Automate MySQL *.sql File Execution in PHP for Website Generation, Considering Zend Framework Compatibility?

Susan Sarandon
Susan SarandonOriginal
2024-12-22 22:42:14936browse

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:

  • Avoid using console access.
  • --execute="SOURCE ..." option is used to execute the file.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn