Connection with Firebird with isql-fb works, but not using PHP or Python

74 Views Asked by At

I have a third-party application that is based on a Firebird database (version 3.0). For statistics and further processing of data, I was thinking of regularly copying the database to a Linux server and making all the data available there via a web interface (PHP/Laravel). Direct access to the database is not possible as data is also changed during processing. However, I am failing to access the database and would like some help.

System: Ubuntu Server 20.04 clean install, with Firebird 3.0 from apt sources in the standard installation, no changes to firebird.conf. Access via isql-fb works, I can perform all queries with it.

$ isql-fb
Use CONNECT or CREATE DATABASE to specify a database
SQL> connect DB.FDB user 'sysdba' password 'password';
Database: DB.FDB, User: SYSDBA
SQL> show tables;
     [list of all tables]

When I try to access via PHP or Python, I get a similar error message in both cases:

Both scripts are minimalist queries from documentation that execute a "show tables" or a "select * from table".

Does anyone have any ideas?

I've tried both connection strings with and without full path. Both scripts are in the same directory as the database.

try {
    $dsn = "firebird:host=127.0.0.1;dbname=DB.FDB;charset=UTF8";
    $pdo = new PDO($dsn, 'sysdba', 'password');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}

$query = $pdo->query("SHOW TABLES");

PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: -104 Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 1 SHOW in /home/user/firebird.php:23

Python 3:

import fdb

con = fdb.connect(
    dsn='localhost:DB.FDB',
    user='sysdba', password='password',
    charset='UTF8' # specify a character set for the connection
)

print(con)
cur = con.cursor()
cur.execute("show tables")
Traceback (most recent call last):
  File "/home/user/firebird.py", line 17, in <module>
    cur.execute("show tables;")
  File "/usr/lib/python3/dist-packages/fdb/fbcore.py", line 3626, in execute
    self._ps = PreparedStatement(operation, self, True)
  File "/usr/lib/python3/dist-packages/fdb/fbcore.py", line 2253, in __init__
    raise exception_from_status(DatabaseError, self._isc_status,
fdb.fbcore.DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -104\n- Dynamic SQL Error\n- SQL error code = -104\n- Token unknown - line 1, column 1\n- show', -104, 335544569)
1

There are 1 best solutions below

0
user13964273 On

SHOW TABLES is exclusively an ISQL command. It is not supported in DSQL as you can see in Language Reference.

To get list of tables in DSQL, you should query system tables such as RDB$RELATIONS.

And BTW Firebase and Firebird are two completely different products.