How do i backup a SQL database using PHP.
Is there a vendor agnostic way to do this that conforms to ANSI SQL?
If not maybe you can list how to do it for each of the database vendors?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every database system comes with some program for dumping its contents.
pg_dumpmysqldumpYou can simply call that program from PHP using
system()orshell_exec().For example, if you use PostgreSQL with enabled Ident authentication and want to dump the Database
testdirectly as SQL text to the browser, it’s as simple as:<?php header('Content-type: text/plain'); system('pg_dump test'); ?>When using MySQL with database user and password stored into
~/.my.cnf, it is also very simple:<?php header('Content-type: text/plain'); system('mysqldump test'); ?>However, don’t do this:
<?php header('Content-type: text/plain'); system('mysqldump -utestuser -ptestpassword test'); ?>because transmitting a password as command line argument is very insecure.