Reputation: 45
now I'm using AWS EC2, RDS
I use CentOS 7 in EC2, and install apache and all php package (include php-mysql)
DB security group Inbound set mysql/aurora IP = myEC2instance and outbound set Default All and mysql/aurora IP = myEC2instance
And I tried connect EC2 to RDS - upload php file in my EC2 via filezilla
The source is here
$host = "myinstance.c8rse3unpyyi.ap-northeast-2.rds.amazonaws.com";
$user = "myUsername";
$pass = "myPW";
$dbname = "testDB";
$conn = mysqli_connect($host, $user, $pass, $dbname, 3306);
if ($conn) {
echo "connect_success";
} else {
echo "connect_fail";
}
# select
$sql = "INSERT INTO test (NAME, NUM)
VALUES ('john', '3')";
if (mysql_query($sql)) {
echo "query_sended!";
} else {
echo "query_failed..";
};
The result is...
connect_success
Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/html/db_connect.php on line 20Warning: mysql_query(): A link to the server could not be established in /var/www/html/db_connect.php on line 20
query_failed..
mysqli_connect is success but mysql_query cannot send!
I tried more inbound rule ex) All TCP, All ICMP, All UDP to ip - EC2 but failed
How can I worked it?
Upvotes: 1
Views: 242
Reputation: 45
I found problem.....
Once use mysqli_connect
then every query send mysqli_query
..
Sorry and THX
Upvotes: 1