<p>How do i backup a SQL database using PHP.</p>

<p>Is there a vendor agnostic way to do this that conforms to ANSI SQL?</p>

<p>If not maybe you can list how to do it for each of the database vendors?</p>

Every database system comes with some program for dumping its contents.
PostgreSQL:
```
pg_dump
```
MySQL:
```
mysqldump
```
...
You can simply call that program from PHP using
```
system()
```
or
```
shell_exec()
```
.
For example, if you use PostgreSQL with enabled
Ident authentication
and want to dump the Database
```
test
```
directly 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 -p
testpassword
test');
?>
```
```
because transmitting a password as command line argument is
very insecure
.