FirebirdSQL / php-firebird

Firebird PHP driver
Other
66 stars 15 forks source link

ibase_connect(): connection rejected by remote interface #47

Closed rtfmfm closed 1 year ago

rtfmfm commented 1 year ago

Hello, I'm trying to connect to an Interbase database that is located on a Windows machine from a Linux (Ubuntu) machine with the following setup:

        $host = '192.168.1.111/3050:C:/Folder/Subfolder/Database.gdb';
        $username = 'SYSDBA';
        $password = 'masterkey';

        $dbh = ibase_connect($host, $username, $password);

        $stmt = 'SELECT * FROM USERS';
        $sth = ibase_query($dbh, $stmt);

        while ($row = ibase_fetch_object($sth)) {
            dump($row);
        }
        ibase_free_result($sth);
        ibase_close($dbh);

But getting the error ibase_connect(): connection rejected by remote interface. Could you advice me where I'm wrong, please?

AlexPeshkoff commented 1 year ago

First of all try to connect with isql - it will quickly show you is the problem with php or something else.

rtfmfm commented 1 year ago

I'm not sure how to do this. Do I have to configure it in the odbc.ini and then use it with isql or use a connect string? Could you, please, provide an example sections for odbc.ini and odbcinst.ini

MartinKoeditz commented 1 year ago

Can you provide firebird.conf. PHP uses legacy auth. Maybe firewall problem. In each case you have to check if you can connect from remote.

ISQL has nothing to do with ODBC. It's a command line tool for Firebird. Have a look at the docs: https://firebirdsql.org/file/documentation/html/en/firebirddocs/isql/firebird-isql.html#isql-start-session

rtfmfm commented 1 year ago

@MartinKoeditz , when I clear the commented lines in my /etc/firebird/3.0/firebird.conf I have only this:

UdfAccess = None
RemoteBindAddress = localhost

I tried to add

WireCrypt = Disabled
AuthServer = Legacy_Auth, Srp, Win_Sspi
AuthClient = Legacy_Auth, Srp, Win_Sspi

and changed WireCrypt to Enabled and Disabled. Same result.

I do not think it is a firewall problem because I'm able to connect to the database using JDBC driver interclient.jar and RazorSQL.

Thank you for the provided documentation! I'll check there too.

rtfmfm commented 1 year ago

I just found out what was my problem with isql. I had installed unixodbc which has the same command. The one delivered with firebird package is isql-fb . This is the result:

➜  ~ isql-fb -user CLEARED -password CLEARED 192.168.1.111/3050:C:/Folder/Subfolder/Database.gdb      
Statement failed, SQLSTATE = 08004
connection rejected by remote interface
Use CONNECT or CREATE DATABASE to specify a database
SQL> 
AlexPeshkoff commented 1 year ago

That means firebird server is not listening on port. Also may be firewall issue.

rtfmfm commented 1 year ago

Okay, I'll explain in more detail. On the windows machine, there is already a running firebird database server on port 3050 and I can connect to it with isql-fb but this is not what I want. On the same windows machine, there is also running Interbase 2017 server on a different port. For the example above, I used 3050 to avoid these long explanations, but here it is.

In short, from my Linux machine, I CAN connect to the firebird server with: isql-fb -user USER -password PASS 192.168.1.111/3050:C:/Somefolder/SomeSubfolder/database.fdb

and I CAN connect to the Interbase 2017 server using RazorSQL with JDBC driver using 3051 port

But I CAN NOT connect to Interbase 2017 server with: isql-fb -user USER -password PASS 192.168.1.111/3051:C:/Folder/Subfolder/database.gdb

I think that if the problem is a firewall, I won't be able to connect with RazorSQL client too.

I tried to mount the folder containing the database from the windows machine locally in my Linux machine and access it that way. In this case, this is the result:

➜  ~ isql-fb -user USER -password PASS localhost:/mnt/windowsMachine/data/database.gdb
Statement failed, SQLSTATE = 08004
file /mnt/windowsMachine/data/database.gdb is not a valid database
-IProvider::attachDatabase failed when loading mapping cache
Use CONNECT or CREATE DATABASE to specify a database
SQL> 

I believe that in this last attempt, it is trying to read the database file as a firebird database, not InterBase and this leads to the error.

Any suggestions and advice would be highly appreciated. Thank you in advance!

mrotteveel commented 1 year ago

That means firebird server is not listening on port. Also may be firewall issue.

Alex, that would be a different error, "Unable to complete network request to host hostname". "connection rejected by remote interface" generally is the result if the op_connect or op_attach fails because the server and client cannot agree on connection options.

AlexPeshkoff commented 1 year ago

On 1/30/23 18:17, rtfmfm wrote:

Okay, I'll explain in more detail. On the windows machine, there is already a running firebird database server on port 3050 and I can connect to it with |isql-fb| but this is not what I want. On the same windows machine, there is also running Interbase 2017 server on a different port. For the example above, I used 3050 to avoid these long explanations, but here it is.

In short, from my Linux machine, I CAN connect to the firebird server with: |isql-fb -user USER -password PASS 192.168.1.111/3050:C:/Somefolder/SomeSubfolder/database.fdb|

and I CAN connect to the Interbase 2017 server using RazorSQL with JDBC driver using 3051 port

But I CAN NOT connect to Interbase 2017 server with: |isql-fb -user USER -password PASS 192.168.1.111/3051:C:/Folder/Subfolder/database.gdb|

If you have not configured interbase to accept unencrypted connections (and may be some else config ...) that's expected - full compatibility was lost long ago. What error do you get here from isql?

I think that if the problem is a firewall, I won't be able to connect with RazorSQL client too.

Certainly.

I tried to mount the folder containing the database from the windows machine locally in my Linux machine and access it that way. In this case this is the resut:

|➜ ~ isql-fb -user USER -password PASS localhost:/mnt/windowsMachine/data/database.gdb Statement failed, SQLSTATE = 08004 file /mnt/windowsMachine/data/database.gdb is not a valid database -IProvider::attachDatabase failed when loading mapping cache Use CONNECT or CREATE DATABASE to specify a database SQL> |

I believe that in this last attempt, it is trying to read the database file as a firebird database, not InterBase and this leads to the error.

Yes.

Any suggestions and advices would be highly appreciated. Thank you in advance!

First of all it will be very useful to know what do you wish to achieve.

mrotteveel commented 1 year ago

I believe that in this last attempt, it is trying to read the database file as a firebird database, not InterBase and this leads to the error.

So what you're saying is that you weren't actually attempting to connect to a Firebird server, but to an InterBase server? I'm not sure if that would even still work these days (and if you can, it is not formally supported, but just an accident of shared heritage). Maybe the PHP driver itself can handle it, but that would require the appropriate connection library from InterBase, and not from Firebird.

In any case, even if this could work, you cannot always copy a database between different platforms like Linux and Windows, which might require performing a backup at the source and a restore on the target. However, if your source is InterBase, this is unlikely to work.

AlexPeshkoff commented 1 year ago

On 1/30/23 18:30, Mark Rotteveel wrote:

That means firebird server is not listening on port. Also may be
firewall issue.

Alex, that would be a different error, /"Unable to complete network request to host hostname"/. /"connection rejected by remote interface"/ generally is the result if the op_connect or op_attach fails because the server and client cannot agree on connection options.

Mark, it's a result of nopt understood by client reply on op_connect. And in a case when firewall sends something like html reply 'Port is closed' our client is rising isc_connect_reject. I believe that's not the most typical reason but I've seen that. In this case (when interbase not firebird is running on remote port) - yes, this sooner of all means interbase does not want to talk using protocol 10 (our last common with IB protocol). But as long as I have not known about use of IB on server I could not imagine such a case...

rtfmfm commented 1 year ago

@AlexPeshkoff

If you have not configured interbase to accept unencrypted connections (and may be some else config ...) that's expected - full compatibility was lost long ago. What error do you get here from isql?

I did not change the default Interbase configuration. Can you tell me what has to be changed? The error is:

➜  ~ isql-fb -user UER -password PASS 192.168.1.111/3051:C:/Folder/Subfolder/database.gdb
Statement failed, SQLSTATE = 08004
connection rejected by remote interface
Use CONNECT or CREATE DATABASE to specify a database

First of all it will be very useful to know what do you wish to achieve.

I just want to connect my PHP app to read from the InterBase database. I do not want to write information back.

@mrotteveel

So what you're saying is that you weren't actually attempting to connect to a Firebird server, but to an InterBase server?...

Yes. That's what I wrote in my first post. I want to connect to InterBase 2017

AlexPeshkoff commented 1 year ago

On 1/30/23 20:08, rtfmfm wrote:

I just want to connect my PHP app to read from the InterBase database. I do not want to write information back.

Sorry, but I suppose that should better be asked not at firebird-related forum. All I can suggest is to use interbase-specific driver, not firebird. The difference in 2023 between them is too big.

rtfmfm commented 1 year ago

@AlexPeshkoff and @mrotteveel , thank you very much for your efforts and your help. Even if this extension is not working with my setup it's good to know that and save some time. Thank you!