Connection to PostgreSQL for PHP Applications
1. Log into the Cloudjiffy.2. Create PHP environment with PostgreSQL database:
3. Check your e-mail - your inbox should have a message with database login and password:
Now, you can upload your PHP application package and deploy it to the environment.
2. Navigate to etc folder and open php.ini file.3. Add extension=pgsql.so line after extension=mysql.so, like it is shown in the image below:
4. Save the changes and Restart nodes for Apache server.
5. There are 2 main PG functions for connection:
- Connection to your postgresql database:
- host - Postgres server address that you received by email (note that it must be without http://):
- port - by default 5432
- dbname - name of your database
- user - by default is "webadmin"
- password - the password that you received via email
Closing connection to postgresql database: pg_close()
All Postgres functions you can see here.6. You need to write necessary functions in every *.php page, which should be connected to the database.
Connection Check Up
- check the connection using this code:
- execute simple request and output it into table:
Now, you can use connection to PostgreSQL database for your PHP application.