Database Connection Strings

 

All instances, created in Apiqcloud, are operated as independent containers. To establish the connection to a database from the application, deployed within an application server, you need to set a connection string for it, using either:

 

CNAME of database, e.g. node{node_id}-{environment_name}.{hoster_domain}.

Private IP address.

Public IP address (if attached).

 

1. Database Connection for Java Application:

   

DB types

Connection Code 

MySQL / MariaDB 

String URL = "jdbc:mysql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MySQL

Auto-Cluster

String URL = "jdbc:mysql://proxy.{environment_name}.{hoster_domain}:3306/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MariaDB

Auto-Cluster

String URL = "jdbc:mariadb://proxy.{environment_name}.{hoster_domain}:3306/{dbname}?usePipelineAuth=false";

DriverManager.getConnection(URL, user_name,user_password);

PostgreSQL

String URL = "jdbc:postgresql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";

DriverManager.getConnection(URL, user_name,user_password);

MongoDB

Mongo m = new Mongo(node{node_id}-{environment_name}.{hoster_domain});

DB db = m.getDB ({database_name});

if (db.authenticate(user_name,user_password.toCharArray())) {

System.out.println("Connected!");

}

 

For the UTF-8 encoding, modify your connection string according to this:

"jdbc:{dbtype}://{dbtype}{node_id}-{environment_name}.{hoster_domain}/{dbname}?useUnicode=yes&characterEncoding=UTF-8"

 

2. Database Connection for PHP Application:

 

DB types

Connection Code 

MariaDB and MySQL 

mysql_connect('HOST', 'USERNAME', 'PASSWORD')

MongoDB

Mongo("hostaddress", array("username" => "username", "password" => "password"))

PostgreSQL

pg_connect("host=host_address port=5432 dbname=postgres user=webadmin password=password")



  • 0 Utilizadores acharam útil
Esta resposta foi útil?

Artigos Relacionados

PostgreSQL Database Replication

Database Replication with PostgreSQL 9 Replication is a basic technology for any database...

Scheduling Databases Backups

Scheduling Database Backups Scheduled backups are data backup processes which proceed...

MongoDB Database Backups

Create an environment 1. Log into your Apiqcloud account and click Create environment. 2. As...

Database Configuration

Database Configuration Below you will see the list of the configuration files available for...

PostgreSQL Database Backups

Automatic PostgreSQL Backups   The instruction below shows how to configure automatic...