Home >Backend Development >PHP Tutorial >PHP uses the exec function to import and export the database
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.