Reputation: 362
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;
}
?>
Error is this:-
ERROR: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Upvotes: 0
Views: 675
Reputation:
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')
Upvotes: 1