[英]EC2 connect RDS using PHP
i know this has been asked but none of the threads had a solution that worked for me 我知道有人问过这个问题,但是没有一个线程对我有用
I am connecting to RDS from XAMPP (local) with success 我成功地从XAMPP(本地)连接到RDS
Also i am connecting fine with mySql workbench 我也与MySql工作台连接良好
Having problems connecting from EC2 从EC2连接时遇到问题
getting error: Fatal error: Call to undefined function mysql_connect()
得到错误: Fatal error: Call to undefined function mysql_connect()
this is what my PHP looks like: 这是我的PHP的样子:
define("HOST", "mydatabase-starter.Pzw9yv81CmMJ.us-east-1.rds.amazonaws.com:3306");
define("DBUSER", "mydatabaseUser");
define("PASS", "**********");
define("DB", "mydatabase");
die("Going to connect now, wish me luck!");
$conn = mysql_connect(HOST, DBUSER, PASS) or die();
$db = mysql_select_db(DB) or die();
also, the security from RDS looks like this! 此外,RDS的安全性看起来就像这样!
EC2 is a lamp stack, fresh install of apache and php, without mysql. EC2是一个灯栈,可以重新安装apache和php,而没有mysql。
what am i doing wrong? 我究竟做错了什么? are there any other services i am missing? 我还缺少其他服务吗?
UPDATE: from SSH, i can connect to RDS by: 更新:从SSH,我可以通过以下方式连接到RDS:
sudo mysql -h mydatabase-starter.Pzw9yv81CmMJ.us-east-1.rds.amazonaws.com -P 3306 -u mydatabaseUser -p
* this will output "Going to connect now, wish me luck!" *这将输出“现在可以连接,祝我好运!” from the PHP file 从PHP文件
but looks like the connection doesnt happen when it is on EC2 但是在EC2上看起来好像没有发生连接
You need the php-mysql. 您需要php-mysql。 I guess you are using Amazon Linux AMI so try 我想您正在使用Amazon Linux AMI,请尝试
sudo yum install php-mysql
It means MySQL extension is not loaded on your EC2 Instance. 这意味着MySQL扩展未加载到您的EC2实例上。 Depending on your distro, you must install it. 根据您的发行版,您必须安装它。
On Debian / Ubuntu, you should run command like this: 在Debian / Ubuntu上,您应该运行以下命令:
$ sudo apt-get install php5-mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.