I am using docker with amazonlinux2 and php already installed on docker. I am trying to connect with sequal ace(mysql database) on mac, trying to run on local. tried with 127.0.0.1 and localhost on the place of hostname here is "db"
here is my code:-
<?php
$con = new mysqli("db","apr","password","lumen_local");
if ($con->connect_errno) {
printf("connection failed: %s\n", $con->connect_error());
exit();
}
$res = $con->query("SELECT VERSION()");
if ($res) {
$row = $res->fetch_row();
echo $row[0];
}
$res->close();
$con->close();
?>
when I am trying with the above code it is showing the following error:-
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'apr'@'amazonlinux-web-1.amazonlinux_default' (using password: YES) in /work/api/test/mysql.php:3 Stack trace: #0 /work/api/test/mysql.php(3): mysqli->__construct('db', 'apr', 'password', 'lumen_local') #1 {main} thrown in /work/api/test/mysql.php on line 3
but when i change the host name from "db" to "127.0.0.1"
with the following code:-
<?php
$con = new mysqli("127.0.0.1","apr","password","lumen_local");
if ($con->connect_errno) {
printf("connection failed: %s\n", $con->connect_error());
exit();
}
$res = $con->query("SELECT VERSION()");
if ($res) {
$row = $res->fetch_row();
echo $row[0];
}
$res->close();
$con->close();
?>
it shows the different error:-
Fatal error: Uncaught mysqli_sql_exception: Connection refused in /work/api/test/mysql.php:3 Stack trace: #0 /work/api/test/mysql.php(3): mysqli->__construct('127.0.0.1', 'apr', 'password', 'lumen_local') #1 {main} thrown in /work/api/test/mysql.php on line 3
I am looking for your support, Thanks in advance!
here is my code:-
<?php
$con = new mysqli("db","apr","password","lumen_local");
if ($con->connect_errno) {
printf("connection failed: %s\n", $con->connect_error());
exit();
}
$res = $con->query("SELECT VERSION()");
if ($res) {
$row = $res->fetch_row();
echo $row[0];
}
$res->close();
$con->close();
?>
<?php
$con = new mysqli("127.0.0.1","apr","password","lumen_local");
if ($con->connect_errno) {
printf("connection failed: %s\n", $con->connect_error());
exit();
}
$res = $con->query("SELECT VERSION()");
if ($res) {
$row = $res->fetch_row();
echo $row[0];
}
$res->close();
$con->close();
?>