[英]Connecting to a mysql database from a separate Application
First time using OpenShift, and I've read that I am able to connect to a database on a different application under my account. 第一次使用OpenShift,并且我读到可以在我的帐户下连接到其他应用程序上的数据库。
I have APPLICATION A that is a Ruby/MySQL project. 我有一个Ruby / MySQL项目的APPLICATIONA。 I have APPLICATION B that is a PHP project. 我有一个PHP项目“ APPLICATION B”。
I'd like to connect to my APPLICATION A MySQL database from my APPLICATION B PHP script. 我想从我的APPLICATION B PHP脚本连接到我的APPLICATION A MySQL数据库。 When doing an rhc apps
command, I can see that my connection URL reads: 当执行rhc apps
命令时,我可以看到我的连接URL显示为:
Connection URL: mysql://$OPENSHIFT_MYSQLDB_HOST:$OPENSHIFT_MYSQLDB_PORT
When looking at my environment variables on my APPLICATION A server, I see they are: 在我的APPLICATION A服务器上查看环境变量时,我看到它们是:
OPENSHIFT_MYSQLDB_PORT=3306
OPENSHIFT_MYSQL_HOST=127.7.171.129
But when I try to connect: 但是当我尝试连接时:
$db = new mysqli('127.7.171.129', 'adminuser', 'adminpw', 'productiondb',3306);
And I dump out this: 我把这个丢掉了:
object(mysqli)#1 (17) {
["affected_rows"]=>
NULL
["client_info"]=>
NULL
["client_version"]=>
int(50169)
["connect_errno"]=>
int(2005)
["connect_error"]=>
string(57) "Unknown MySQL server host 'http://127.7.171.129' (1)"
["errno"]=>
NULL
["error"]=>
NULL
["field_count"]=>
NULL
["host_info"]=>
NULL
["info"]=>
NULL
["insert_id"]=>
NULL
["server_info"]=>
NULL
["server_version"]=>
NULL
["sqlstate"]=>
NULL
["protocol_version"]=>
NULL
["thread_id"]=>
NULL
["warning_count"]=>
NULL
}
Here's a KB article that has a couple of suggestions: https://www.openshift.com/kb/kb-e1051-how-do-i-connect-multiple-applications-to-one-database 这是一篇包含一些建议的知识库文章: https : //www.openshift.com/kb/kb-e1051-how-do-i-connect-multiple-applications-to-one-database
Can you take a look to see if it helps? 您可以看看是否有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.