ScotlandPHP 2016


(PHP 5)

ibase_connect Apre una connessione con un database InterBase


resource ibase_connect ( string $database [, string $username [, string $password [, string $charset [, int $buffers [, int $dialect [, string $role ]]]]]] )

Stabilisce una connessione con un server InterBase. Il parametro database deve essere un percorso valido di un file di database sul server dove risiede. Se il server non fosse locale, bisogna aggiungere prima del percorso o 'hostname:' (TCP/IP), o '//hostname/' (NetBEUI) o 'hostname@' (IPX/SPX), in base al protocollo di connessione utilizzato. username e password possono venire specificati anche con le direttive di configurazione del PHP ibase.default_user e ibase.default_password. charset è il set di caratteri predefinito per un database. buffers è il numero di buffer di database da allocare per la cache dal lato server. Se è 0 o viene omesso, il server usa il suo valore predefinito. dialect seleziona il dialetto SQL predefinito per ogni operazione eseguita all'interno di una connessione, e il suo valore predefinito è il più alto supportato dalle librerie del client.

Nel caso di una seconda chiamata fatta con ibase_connect() con gli stessi parametri, non verrà creato alcun nuovo collegamento, bensì, l'identificatore del collegamento già aperto verrà restituito. Il collegamento al server verrà chiuso appena termina l'esecuzione dello script, a meno che non venga chiuso prima esplicitamente chiamando ibase_close().

Example #1 Esempio di ibase_connect()


$dbh ibase_connect($host$username$password);
$stmt 'SELECT * FROM tblname';
$sth ibase_query($dbh$stmt);
    while (
$row ibase_fetch_object($sth)) {
$row->email "\n";


Il parametro opzionale buffers è stato aggiunto in PHP 4.0.0.


dialect è stato aggiunto in PHP 4.0.0. E' funzionante solo con InterBase 6 e versioni successive.


role è stato aggiunto in PHP 4.0.0. E' funzionante solo con InterBase 5 e versioni successive.


Se si verificano degli errori tipo "arithmetic exception", "numeric overflow", oppure "string truncation. Cannot transliterate character between character sets" (questo capita quando si tenta di usare dei caratteri accentati) questa funzione o dopo la funzione ibase_query(), occorre impostare il set di caratteri (ad esempio ISO8859_1 oppure il set di caratteri corrente).

Vedere anche: ibase_pconnect() e ibase_close().

add a note add a note

User Contributed Notes 7 notes

anthony at trams dot com
15 years ago
If you get a message like: 'Dynamic SQL Error SQL error code = -901 feature is not supported', this may be caused by InterBASE client 6.01 accessing a server running 5.x.

Make sure the dialect value is set to '1', like the following:

ibase_connect ('localhost:/usr/db/db.gdb', 'SYSDBA', 'masterkey', 'ISO8859_1', '100', '1' ) ;

That last value is the dialect, but you need the two preceding also, do avoid errors.

ag at dividi dot de
10 years ago
With php5 on Windows i couldnt connect to a firebird database with following error :

Warning: ibase_connect(): Unable to complete network request to host "localhost"
. Failed to locate host machine. Undefined service gds_db/tcp.  in C:\\wamp\\php\\ibase.php on line 5

the connect command was "$dbh = ibase_connect ("localhost:path_to_file.fdb", $username, $password);"

The solution is to insert the line
gds_db    3050/tcp    #firebird Database
into the windows services file %WINDIR%\\system32\\drivers\\etc\\services
simon at thorndancer dot com
13 years ago
I found it difficult to get anything working using the current documentation.
While logic would suggest that the format in the docs should work (being based on all the
syntax of other standard database access functions) I had problem after problem. Finally I
found some comments on a newgroup that helped, and this is the result.

This is actual production code (not a mere example). It works.
Don't ask me why it is so different from the official docs.

if ( ibase_connect( $db_filespec,$db_user,$db_pass_word) )
    $query  = "SELECT, c.title, c.description ";   
    $query .= "FROM collections c ";  
    $query .= "WHERE ( = $page_id) ";                                      

    $result = ibase_query( $query );

    $row_array = ibase_fetch_row($result);

    $row_fetched = !empty($row_array);

    if ($row_fetched)     
       // Extract the row into variables

        $collection_id   = $row_array[0];           
       $edit_title      = $row_array[1];           
       $edit_desc       = $row_array[2];           

       // Standardise the record contents

        $collection_id   = $collection_id + 0;      // force type to numeric

    // Wrap up the database side of things

     ibase_commit();     // note parenthesis but no parameters.

     ibase_close;        // note total lack of parenthesis and parameters !
You'll notice that there is no reference to a database handle in this code.
It seems to be implicit when dealing with interbase functions. Certainly, I couldn't
get the code to work when using it explicitly. This makes the documentation
very hard to work with, and any reference to a handle needs to be ignored.

Important: ibase_close doesn't work for me if I put parenthesis after it.
        ibase_close;        // works
        ibase_close();      // fails
        ibase_close($db);   // fails
Note: the line "if ($row_fetched)" could be replaced with "while ($row_fetched)"
if you need to process more than one record.

All that said, Interbase is a fantastic database to work with and IMHO a much
better choice than something like PostgreSQL if you need to move up from MySQL
to something more industrial strength. Just be sure to RTFM.
fwrk at bk dot ru
1 year ago
If you want to connect to interbase server runned on custom port (not default port 3050), you can specify it in "database" parameter in this way: 'hostname/port:' (TCP/IP with custom port).
$dbh = ibase_connect('', $username, $password);
$dbh = ibase_connect('', $username, $password);
$dbh = ibase_connect('\\data\\mywinibase.fdb', $username, $password);
fb dot bird at gmail dot com
9 years ago
Remember for different locations
of php.ini file:


Please do not confuse this
and know location _loaded_ *.ini-file!
Robert Silvia
11 years ago
Just to update Simon's note...

Things must have been fixed since Simon wrote that note.
With PHP5 the following example works flawlessly:

$strconnect = 'localhost:/opt/firebird/examples/employee.fdb';

if (!($db=ibase_connect($strconnect, 'sysdba', 'yourpass', 'ISO8859_1', 0, 1)))
    die('Could not connect: ' .  ibase_errmsg());

  $cursor = ibase_query($sql);
  $row_array = ibase_fetch_row($cursor);


Also you CAN get away with the following connection string:
ibase_connect('/opt/firebird/examples/employee.fdb', 'sysdba', 'yourpass')
sam at
12 years ago
If you get a sloooow work of ibase_connect on Win2003, try to update your FireBird to version 1.5 or above, and your InterBase to version 7.1. Or move back to Win2000 :)
To Top