1
votes

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
Also i am connecting fine with mySql workbench
Having problems connecting from EC2

getting error: Fatal error: Call to undefined function mysql_connect()

this is what my PHP looks like:

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!enter image description here
EC2 is a lamp stack, fresh install of apache and php, without mysql.
what am i doing wrong? are there any other services i am missing?

UPDATE: from SSH, i can connect to RDS by:
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
but looks like the connection doesnt happen when it is on EC2

2
Are you getting anything useful from mysql_error() after the connect fails? - keithhatfield
i dont get an output, its like the connection doesnt even happen when its on AWS - t q
Hmm. Is port 3306 on your EC2 instance allowing outbound traffic? - Daan
3306 > out? where can i check this? - t q
Quickest way is probably the Amazon EC2 online management panel. Log in at the top right of the page, click through to EC2, and look at the security settings for your instance. - Daan

2 Answers

5
votes

You need the php-mysql. I guess you are using Amazon Linux AMI so try

sudo yum install php-mysql
1
votes

It means MySQL extension is not loaded on your EC2 Instance. Depending on your distro, you must install it.

On Debian / Ubuntu, you should run command like this:

$ sudo apt-get install php5-mysql