Home >Backend Development >PHP Tutorial >PHP uses the exec function to import and export the database

PHP uses the exec function to import and export the database

WBOY
WBOYOriginal
2016-07-29 09:11:431626browse

Export database code:

exec("mysqldump -h localhost -uroot -ppassword --default-character-set=utf8 dbname>d:/aaa.sql 2>&1", $output, $return_val) ;exit;

Notes: 1) There must be a space between -h and localhost (otherwise the output will report an incorrect password error)

2) There must be no space between -u and root, -p and password ( If there is a space output result in the middle)

3)-Default-Character-set = UTF8 (the font format used to set the exported document)

4) 2 & gt; After adding 2>&1, it will be printed in the document

Import database code:

exec("mysql -h localhost -uroot -ppassword dbname< d:/ccc.sql ");exit;

The above introduces how PHP uses the exec function to import and export the database, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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