Connection to DB2 Native ODBC
At Scriptcase, we have the following drivers available for connection to DB2: DB2 and DB2 Native ODBC. If you are using your own, pre-configured environment , DB2 extensions must be enabled manually in PHP.
Note: The steps described in this documentation are only valid for Mac devices that have CPU with x64 architecture
Installing IBM DSDRIVER
Download the IBM DSDRIVER installer
- IBM DsDriver: Click here
Follow the steps below to install correctly.
1 - Double-click the v11.1.1fp1_macos_dsdriver.dmg file
A new Finder window will open with the contents of the disk image.
2- Run the installation script:
-
In the Finder window, locate the
installDSDriver.sh.
file -
Double-click the
installDSDriver.sh
file to start the installation. -
The driver package will be installed in the default location: /Applications/dsdriver.
Setting the environment variables
For PHP to recognize the Db2 driver, set the following environment variables:
Open the ~/.bash_profile or ~/.zshrc file (depending on the shell you are using) in a text editor and add the following line
export IBM_DB_HOME=/Applications/dsdriver
export DYLD_LIBRARY_PATH=$IBM_DB_HOME/lib
export PATH=$IBM_DB_HOME/bin:$PATH
Save the file and run the following command to apply the changes:
source ~/.bash_profile or source ~/.zshrc
Configuring the ODBC Driver Manager
1 - Open ODBC manager, and in Driver tab, add DB2 native driver. Specify ‘DB2 Native Driver’ in the ‘Driver Name’ slot and ‘/Applications/dsdriver/lib/libdb2.dylib’ in the ‘Driver File’ slot - no other information is required here.
2 - In the ‘System DSN’ tab of ODBC Manager create a DB2 DSN
- In the “Choose a Driver” slot specify the ‘DB2 Native Driver’ you defined above
- Specify a DSN in the ‘Data Source Name (DSN) slot, eg. ‘db2’ and click on ‘Add’ to create the system DSN.
Setting the db2dsdriver.cfg file
Before creating the connection in the Scriptcase interface, you need to set up the file db2dsdriver.cfg
The file may be named db2dsdriver.cfg.sample. Just create a copy of this file and rename it to db2dsdriver.cfg
If you can’t find the file, you can also create it manually.
1 : Open the db2dsdriver.cfg file located in /Applications/dsdriver/cfg/ and configure the file as shown in the structure below and then save.
<configuration>
<dsncollection>
<dsn alias="db2" name="db2" host="hotel53.torolab.ibm.com" port="5000" ldap=1/>
</dsncollection>
<databases>
<database name="SAMPLE" host="hotel53.torolab.ibm.com" port="5000">
</database>
</databases>
</configuration>
The .cfg file must correspond to the configuration made in the ODBC manager, i.e., the alias and name of the DSN must be the same as that specified in step 2 of the ODBC Driver Manager configuration.
After configuring the file, restart Apache and create the connection.
Automatic Installation | Manual Installation |
---|---|
sudo service apachesc9php81 restart |
sudo service apache2 restart |
Creating a Connection in Scriptcase
See below how to create a connection in your Scriptcase project, using the enabled Driver and the DB2 database.
1 - Access a project from your Scriptcase.
2 - Click the New Connection icon to create a connection
or access the Database > New connection menu.
After that, a screen will appear with all database connections.
3 - Select the DB2 connection.
Connection
Enter the parameters for connecting to your 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 Driver for connection. In this example, we use the DB2 ODBC Genérico driver.
- Server/Host (Name or IP): Enter the System DSN created in the ODBC Data Source.
-
EX:
db2
- 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 .
- 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 database.
-
Password: Enter the password to complete the authentication process.
- Test connection: Click this button to get a response to the Scriptcase request to find out if the parameters entered are correct.
Security
Here are the security options available for a DB2 connection and their descriptions:
Security
Defines the security mechanism used for the connection. It can include options like SSL, Kerberos, or other authentication protocols.
sslservercertificate
Specifies the server’s SSL certificate file used to establish a secure connection. This helps verify the identity of the database server.
sslclientkeystoredb
Refers to the client-side keystore database file that contains SSL certificates and keys necessary for encrypted communication with the DB2 server.
sslclientkeystash
The keystore stash file that contains the encrypted password for the keystore database, allowing the client to access SSL keys securely without manual intervention.
Authentication
Defines the authentication method used for connecting to the DB2 server. It can include methods such as SERVER, CLIENT, or GSSAPI.
sslclientlabel
Specifies the label of the client certificate stored in the keystore database. This helps identify which certificate should be used when multiple certificates exist in the keystore.
Filter
Accessing this tab, you can configure which Database items will be displayed on the connection, depending on the owner or not.
Show
It allows the 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: Selecting this option, the tables in your database will be displayed.
- By default, Scriptcase enables this option .
- 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 .
- By default, Scriptcase enables this option .
-
System Tables: 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 .
- EX:
- Owner: Inform the user who sees the tables informed for display.
- User must be capitalized as in the example above .
- User must be capitalized as in the example above .
- View: 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 settings 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 client_encoding UTF-8.
- By default, this option is left blank by Scriptcase .
- By default, this option is left blank by Scriptcase .
- Decimal Separator: Select the type of separator for decimal records, between comma and period.
- By default, the
.
dot is selected as a separator .
- By default, the
- Persistent Connection: Define whether connections will be closed after the execution of your scripts in Scriptcase applications.
- By default, Scriptcase disables this option .
- By default, Scriptcase disables this option .
- Use the schema before the table name: Define whether the database schema will be displayed before the table names.
- By default, Scriptcase enables this option .
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.
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.