我尝试使用OPENSHIFT中的PHP脚本连接phpmyadmin数据库
i am using sftp to upload file in openshift
这样做是为了连接
的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;
}
?>
错误是这样的: -
错误:SQLSTATE [HY000] [2002]无法通过socket'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2)
答案 0 :(得分:1)
DB_NAME不正确,您应该使用自己的应用名称,为什么还要使用getenv中的值?您应该使用环境变量的名称,例如 GETENV(&#39; OPENSHIFT_MYSQL_DB_HOST&#39)