English 中文(简体)
EC2 使用 PHP 连接 RDS
原标题: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
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

最佳回答

我想你用的是亚马逊Linux AMI,所以试试看

sudo yum install php-mysql
问题回答

这意味着 MySQL 扩展名未装入您的 EC2 程序。 您必须安装它 。

在Debian / Ubuntu 上, 您应该这样运行命令 :

$ sudo apt-get install php5-mysql




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签