本文介绍了如何在Openshift中打开数据库连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在PHP中的dbcon文件.基本上,我需要将PHP应用程序与openshift MySQL DB连接.这就是我所做的.
This is my dbcon file in PHP.Basically, I need to connect my PHP application with openshift MySQL DB. Here's what I did.
<?php
// Database Connection Setting
$dbhost = "127.0.0.1"; // Host name
$dbport = "3308"; // Host port
$dbusername = "user"; // Mysql username
$dbpassword = "pass"; // Mysql password
$db_name = "mf"; // Database name
$mysqlCon = mysqli_connect($dbhost, $dbusername, $dbpassword, "", $dbport) or die("Error: " . mysqli_error($mysqlCon));
mysqli_select_db($mysqlCon, $db_name) or die("Error: " . mysqli_error($mysqlCon));
?>
这在openshift上给我一个错误,但可用于其他PHP应用程序.我对错误的解释一无所获,仅是错误:{...空白空间...}.
This gives me an error on openshift but works for other PHP apps. I get nothing on error explanation only as Error: { ...blank space... }.
推荐答案
我已经做到了这一点.
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'));
$dbhost = constant("DB_HOST"); // Host name
$dbport = constant("DB_PORT"); // Host port
$dbusername = constant("DB_USER"); // MySQL username
$dbpassword = constant("DB_PASS"); // MySQL password
$db_name = constant("DB_NAME"); // Database name
或者
$dbhost = getenv('OPENSHIFT_MYSQL_DB_HOST'); // Host name
$dbport = getenv('OPENSHIFT_MYSQL_DB_PORT'); // Host port
$dbusername = getenv('OPENSHIFT_MYSQL_DB_USERNAME'); // MySQL username
$dbpassword = getenv('OPENSHIFT_MYSQL_DB_PASSWORD'); // MySQL password
$db_name = getenv('OPENSHIFT_GEAR_NAME'); // Database name
这篇关于如何在Openshift中打开数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!