Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to connect to the database in openshift application

I did as following

MySQL 5.1 database added. Please make note of these credentials:

    Root User: xxxxxxx
    Root Password: xxxxxxx
    Database Name: php


 Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/

You can manage your new MySQL database by also embedding phpmyadmin-3.4. The phpmyadmin username and password will be the same as the MySQL credentials above.

phpMyAdmin 3.4 added. Please make note of these MySQL credentials again:

    Root User: xxxxxxx
    Root Password: xxxxxxx

    URL: https://php-doers.rhcloud.com/phpmyadmin/

and i try to connect db using bellow PDO code .but it does not work

$dbh = new PDO('mysql:host=mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/;dbname=php', "xxxxxx, "xxxxxx");

I don't know what is the connection URL mean ?

like image 480
Sami Avatar asked Apr 10 '13 08:04

Sami


People also ask

How do I connect to MySQL in OpenShift?

You may now connect from the Workbench: Standard TCP/IP, host: 127.0. 0.1 port 13306 (Note that the local port is set to 13306 and not the default 3306. You may forward 3306 to 3306 if you prefer, but if you have a local db instance on your computer running on the same port, the forwarding will eventually fail.)

How do I connect to OpenShift cluster?

Procedure. To log in to your cluster, complete the following steps: From a command window, run the oc login command and provide the OpenShift Container Platform server URL (and optionally a token). Indicate whether to use insecure connections, and then specify a user name and password if required.

What is OpenShift database?

OpenShift is a family of containerization software products developed by Red Hat. Its flagship product is the OpenShift Container Platform — a hybrid cloud platform as a service built around Linux containers orchestrated and managed by Kubernetes on a foundation of Red Hat Enterprise Linux.


1 Answers

There is an error in your connection string plus $OPENSHIFT_MYSQL_DB_* are env variables and need to be fetched via getenv php function.

So try the following:

define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT')); 
define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));

$dsn = 'mysql:dbname='.DB_NAME.';host='.DB_HOST.';port='.DB_PORT;
$dbh = new PDO($dsn, DB_USER, DB_PASS);
like image 179
Sumana Mehta Avatar answered Sep 28 '22 05:09

Sumana Mehta