0

i am try to connect phpmyadmin database using my php script in OPENSHIFT
i am using sftp to upload file in openshift
doing this for connection

index.php

<?php 
 try {
                require_once 'conf.php';
                $conn = mysqlConnector();
                $stmt = $conn->prepare('SELECT * FROM demo');
                $stmt->execute();

                while($row = $stmt->fetch()) {
                        print_r($row);          
                }


        } catch(PDOException $e) {
                echo 'ERROR: ' . $e->getMessage();
        }

?>

conf.php

<?php
define('DB_HOST', getenv('127.*.**.*'));
define('DB_PORT',getenv('****')); 
define('DB_USER',getenv('admin4*****'));
define('DB_PASS',getenv('databasePassword'));
define('DB_NAME',getenv('ssh://5348030a***************@landbayscaling-innovifytest.rhcloud.com/~/git/landbayscaling.git/'));

function mysqlConnector(){
    $dsn = 'mysql:dbname='.DB_BASE.';host='.DB_HOST.';port='.DB_PORT;
    $dbh = new PDO($dsn, DB_USER, DB_PASS);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
    }
?>

Url Of Opensift

Error is this:-

ERROR: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

1
  • did you fin a solution for this? Commented Jan 16, 2015 at 4:45

1 Answer 1

1

DB_NAME is incorrect, you should use your app name, also, why are you using the values inside of getenv? You should be using the names of the environment variables, such as getenv('OPENSHIFT_MYSQL_DB_HOST')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.