Go to Scriptcase store

# Connecting with PostgreSQL PDO

In Scriptcase, we have the following drivers available for connections with PostgreSQL: PostgreSQL PDO, PostgreSQL 7 or Higher, PostgreSQL 6.4 or Higher and PostgreSQL 6.3 or Lower. If you are using your own pre-configured environment, PostgreSQL extensions must be manually enabled in PHP.

## Prerequisites

If you are using a manual installation on MacOS, you’ll need to install the PHP and the PostgreSQL driver will be enabled. Click here to see how to do it.

1 - Check if the PostgreSQL driver is enabled in your Scriptcase diagnosis. See below on how to locate your diagnosis and check if the driver is enabled.

- Accessing the top menu Help > Diagnosis, you can easily find it through the interface.

![Accessing diagnosis - Help Menu][diagnosis_sc]

- Or, by accessing your Scriptcase installation path:

`127.0.0.1/scriptcase/diagnosis.php` or `domain.com/scriptcase/diagnosis.php`

## Creating a Connection in Scriptcase

See below how to create a connection in your Scriptcase project using the PostgreSQL database.

1 - Access any project from your Scriptcase.

2 - Click on the New Connection icon to create a connection.

or access the Database > New Connection menu tab.

After that, a new page will appear with all database connections.

3 - Select the Postgres connection.

### Connection

Enter the parameters for connecting to your PostgreSQL database as follows:

- Connection Name: Define the name of your new connection. By default, Scriptcase adds the prefix conn along with the database name.

- DBMS Driver: Select the PostgreSQL Driver used to connect. In this example, we use the PostgreSQL PDO Driver.

- Server/Host (Name or IP): Enter the IP or domain of the server where the database is installed.
  - E.g. `serverdomain.com` or `192.168.254.170`

- Port: Inform the number port for your database server.

- Schema: Inform the Scheme of specific tables created for the use of the informed user.
  - This item is optional if you do not have a schema configured in your database.

- Username: Inform the user to authenticate the connection to your PostgreSQL database.

- Password: Enter the password to complete the authentication process.

- Database Name: Type your database name to connect with him. Or, if you want to choose one different database, click on the button List Database to show all databases availabes for your user.
  - Create Database: Clicking on this button, you will create a new PostgreSQL database for use.
- Test Connection: Click on this button to get a response from the Scriptcase request to find out if the parameters entered are correct.

### Security

#### Use SSL

Allows you to define whether the connection will use SSL. Note that the option is disabled by default.

### sslmode

sslmode | protection | MITM protection | Statement
--- | --- | --- | ---
disable | No | No | I don’t care about security, and I don’t want to pay the overhead of encryption.
allow | Maybe | No | I don’t care about security, but I will pay the overhead of encryption if the server insists on it.
prefer | Maybe | No | I don’t care about encryption, but I wish to pay the overhead of encryption if the server supports it.
require | Yes | No | I want my data to be encrypted, and I accept the overhead.
verify-ca | Yes | Depends on CA policy | I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server that I trust.
verify-full | Yes | Yes | I want my data encrypted, and I accept the overhead. I want to be sure that I connect to a server I trust, and that it’s the one I specify.

#### sslrootcert (SSL Root Certificate)

This parameter refers to the SSL/TLS root certificate used to verify the authenticity of the certificate presented by the server during secure communication. Usage: The value of this parameter must be the full path to the file containing the root certificate.

#### sslkey (SSL Private Key)

This parameter represents the private key associated with the SSL/TLS certificate used by the server for authentication. Usage: The full path to the file containing the private key must be specified.

#### sslcert (SSL Certificate)

The sslcert parameter refers to the server’s SSL/TLS certificate, which is presented during the security negotiation process for authentication. Usage: The full path to the file containing the server’s SSL/TLS certificate must be provided.

### Filter

Accessing this tab, you can configure which Database items will be displayed on the connection, depending or not on the owner.

#### Show

It allows the PostgreSQL connection to see tables, views, system tables and procedures depending on the items selected by the user. By default, the items Tables and Views are already selected by Scriptcase.

- Tables: By selecting this option, the tables in your database will be displayed.
  - By default, Scriptcase enables this option.
- Views: By selecting this option, the views of your database will be displayed.
  - By default, Scriptcase enables this option.

- System Tables: By selecting this option, the system tables of your database will be displayed.

- Procedures: By selecting this option, the procedures of your database will be displayed.

#### Searches

Allows you to define which tables and owners are displayed.

- Tables: You can define in this option which tables will be displayed. The configuration can contain a `PREFIX%` or name of the tables to display.
  - By default, Scriptcase leaves this option empty.
  - E.g.

- Owner: Inform the user who sees the tables entered for display.
  - The user must be in capital letters as in the example above.
- Show: Choose whether tables for the informed owner are displayed.

> NOTE: By using table filtering, you eliminate unnecessary tables for your project and improves the performance of your database connection.

### Advanced

In this tab, you have access to specific settings for the connection. The changes made in this session impact the data display and application performance.

- client_encoding: Select the encoding used in your database. In the example above, we use the client_encoding UTF-8.

- Decimal Separator: Select the type of separator for decimal records, between comma and period.
  - By default, the period `.` is selected as a separator.
- Persistent Connection: Define whether the connections will be closed after the execution of your scripts in Scriptcase applications.
  - By default, Scriptcase disables this option.
- Use the schema before table name: Define whether the database schema is displayed before the table names.

  - By default, Scriptcase enables this option.

  - E.g.

### SSH

Here are the SSH options available in the image and their descriptions regarding database connection:

#### Use SSH

Enables or disables the SSH tunnel for database connection. When enabled, the database connection will be routed through the SSH server.

#### SSH Server

The IP address or hostname of the SSH server that will be used for tunneling. This is the machine that will act as a bridge to access the database securely.

#### SSH Port

The port used to connect to the SSH server.

#### SSH User

The username used to authenticate with the SSH server. This user must have permissions to establish an SSH connection.

#### Authentication method

You can choose two options: password or certificate. When you choose one of the options, a new field will appear below for the configuration.

#### Private cert. file

The private key file used for authentication if the SSH server requires key-based authentication instead of a password.

#### Local port for port forwarding

The local port on the client machine that will be used for forwarding database traffic through the SSH tunnel. This port acts as a bridge between the database client and the remote database.

#### Database server from SSH

The hostname or IP address of the database server as seen from the SSH server. This is necessary when the database is only accessible within the SSH server’s network.

#### Database port from SSH

The port of the database server that will be accessed through the SSH tunnel. This should match the database service’s listening port.