I have connected my appication with aws rds with the script below:
function db_connect() {
$result = new mysqli($_SERVER['RDS_HOSTNAME'], $_SERVER['RDS_USERNAME'], $_SERVER['RDS_PASSWORD'], $_SERVER['RDS_DB_NAME'], $_SERVER['RDS_PORT']);
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
It was working fine then i had to change it due to a new feature which someone else wrote the code for:
$dbOptions = array(
'db_host' => 'RDS_HOSTNAME',
'db_user' => 'RDS_USERNAME',
'db_pass' => 'RDS_PASSWORD',
'db_name' => 'RDS_DB_NAME'
);
I didn't add the port because he didn't and i never connected to database with an array and key like this, how do i go about adding port like at what position.
I was forgetting the $_SERVER variable:
$dbOptions = array(
'db_host' => $_SERVER['RDS_HOSTNAME'],
'db_user' => $_SERVER['RDS_USERNAME'],
'db_pass' => $_SERVER['RDS_PASSWORD'],
'db_name' => $_SERVER['RDS_DB_NAME']
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.