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)
Refer to the appropriate section below based on your environment’s engine:
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
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”) |