Database Connection Strings

In the platform, each instance operates as an independent container. To connect your application to a database, you need to configure a connection string. This can be done using:

  • CNAME of the database (e.g., node{node_id}-{environment_name}.{hoster_domain})
  • Private IP address
  • Public IP address (if attached)
Note: Using localhost in a connection string will not work for connecting your application to the database.

Refer to the appropriate section below based on your environment’s engine:

Save $100 in the next
5:00 minutes?

Register Here

Database Connection for Java Apps

Refer to the table below to find the appropriate database connection code for your application:

DB Type 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 High-availability connection using scaled dedicated ProxySQL load balancers.

String URL = “jdbc:mysql://proxy.{environment_name} .{hoster_domain}:3306/{dbname}”; DriverManager.getConnection(URL, user_name,user_password);

MariaDB Auto-Cluster High-availability connection using scaled dedicated ProxySQL load balancers.

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 UTF-8 encoding, modify your connection string as follows:

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

*hoster_domain: app.cp-accuweb.cloud

Save $100 in the next
5:00 minutes?

Register Here

Database Connection for PHP Apps

Depending on the database type, use the following connection code examples and adjust your application accordingly:

DB Type Connection code
MySQL and MariaDB 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”)
Note: Ensure to specify the host string without http://. The appropriate address and credentials are provided in the email you received upon database creation.

Save $100 in the next
5:00 minutes?

Register Here