catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Medoo ignores host IP. #1067

Closed WizardMuckee closed 1 year ago

WizardMuckee commented 1 year ago

Information

Trying to connect using arguments from env vars. I've checked that the variables contain the correct data.

I want to connect to a remote host but, no matter what I define as the URI, the request is always made to the local IP.

Detail Code

I've changed the actual IP addresses

            $db = new Medoo([
                'type' => $dbSettings['DB_TYPE'],
                'database' => $dbSettings['DB_NAME'],
                'host' => $dbSettings['DB_SERVER'], // This is a remote server on my local network, assume 192.168.0.2
                'username' => $dbSettings['DB_USER'],
                'password' => $dbSettings['DB_PASS'],
                'error' => PDO::ERRMODE_WARNING
            ]);

Expected output I expect an instance of Medoo to be created which connects to the remote address 192.168.0.2, as defined within the DB_SERVER setting.

Actual output SQLSTATE[HY000] [1045] Access denied for user 'myuname'@'192.168.0.1' (using password: YES)

Where the 192.168.0.1 address is the IP of the local server and it should actually be the value of the 'host' argument I pass to the Medoo constructor, 192.168.0.2.

catfan commented 1 year ago

Medoo did nothing change for the host value pass to the PDO connection.

You may check out your $dbSettings['DB_SERVER'] value.

Or output the $database->dsn value to see the final DSN string for the database connection.

WizardMuckee commented 1 year ago

Oh yeah my bad... been away from MySQL for a while and was misinterpreting the error.

I had thought it meant I failed authentication whilst connecting to the displayed IP (my local machine), but actually the error was telling me that the displayed IP failed to connect to the server.

Just had to give the user more privileges.