+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP PostgreSQL database backup.

  1. #1
    javilla is offline x10Hosting Member javilla is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    8

    PHP PostgreSQL database backup.

    Is there anyway to dump a database from a SQL query on PostgreSQL?

    I want to do that from a PHP script. So if there ins't any way to do it from a query, is there any PHP function to do it?

    Thanks a lot,
    Javier.

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP PostgreSQL database backup.

    You can get an array of all the tables using the query "select * from information_schema.tables where table_schema='public' and table_type='BASE TABLE'" Then, you can use "select * from $table" to get all the rows in the table. Then, you can dump it in whatever format you want. I can't think of another way to do it programatically.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    javilla is offline x10Hosting Member javilla is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    8

    Re: PHP PostgreSQL database backup.

    Thank you garrettroyce,

    At last I do it with pg_dump through the PHP function passthru() to get the file. The problem was setting the password. You can force pg_dump to prompt for a password by the -W option. But, what if you want to pass the password to the command to avoid the need to prompt?

    I've found you can set an enviroment variable called "PGPASSWORD" (setenv() in PHP) which will be used by pg_dump. I don't know why that is not documented on postgresql.org but it works.

    Regards,
    Javier

+ Reply to Thread

Similar Threads

  1. php & database help
    By playdnd in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 12-05-2007, 10:55 PM
  2. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  3. search database with php
    By niahossain in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 10-17-2007, 11:06 AM
  4. SQL database backup
    By ShadowStriker in forum Free Hosting
    Replies: 9
    Last Post: 05-31-2005, 05:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers