Thread: Creating a new database at runtime.

Creating a new database at runtime.

From
"Marcel Wolf"
Date:

Hello

I am trying to do the following:

            1. startup my php app

2. check for its database under pgsql

3. If its not there it create it.

4. This may happen for several different apps. I add new apps all the time.

 

Attempts:

1.I have tried to connect to the database and check the error for absence(pg_database) and then try to create it. This fails because the DATABASE missing is fatal.

2. I have tried to connect to template1 and check pg_database for my database and if it is not there create it.

            a. This works but I get the following warning, myindex is a serial field for my database. Do test this I go into phpPgAdmin and drop the addressbook database. Then I open my app to this error. When I refresh the screen everything works?!

 

 

Warning: pg_query(): Query failed: ERROR: relation "info_myindex_seq" already exists . in /usr/local/apache2/htdocs/AddressBook/index.php on line 128
Could not create info tableERROR: relation "info_myindex_seq" already exists

 

 

3. If I repeat this sequence with a different app. It is the same performance but the new app has its tables and the tables from the first database?!

4. I have tried turning on the sql_inheritence to false without any help.

5. I cannot connect to template0.

 

 

 

I do not understand the template0 concept, I am coming from the MYSQL world. Is there a way to do this?????????

 

 

Marcel