If you have this problem:
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
This is because php is deployed with old client library gds32.dll.
To resolve this, update this library to Firebird latest version of fbclient.dll, of course, rename it to gds32.dll and overwrite into php dir.
Or simply don't use localhost ou 127.0.0.1, use computer name.
ibase_connect
(PHP 4, PHP 5)
ibase_connect — Otwiera połączenie do serwera Firebird/InterBase
Opis
Nawiązuje połączenie z serwerem Firebird/InterBase.
W przypadku ponownego wywołania funkcji ibase_connect() z takimi samymi argumentami, nie jest otwierane nowe połączenie, jednak w to miejsce powinien zostać zwrócony identyfikator już otwartego połączenia. Połączenie do serwera powinno zostać zamknięte wkrótce po tym, gdy wykonywanie skryptu PHP się zakończy, o ile nie zostanie zamknięte wcześniej przez jawne wywołanie funkcji ibase_close().
Parametry
- baza_danych
-
Parametr baza_danych jest ścieżką do pliku bazy danych (lub aliasem zapisanym w pliku aliases.conf) na serwerze, na którym się ona znajduje. Jeżeli serwer nie jest uruchomiony lokalnie, to ścieżka musi być poprzedzona łańcuchem 'nazwa_hosta:' (TCP/IP), '//nazwa_hosta/' (NetBEUI) lub 'nazwa_hosta@' (IPX/SPX), w zależności od używanego protokołu.
- użytkownik
-
Nazwa użytkownika. Może być ona ustawiona za pomocą dyrektywy konfiguracyjnej PHP ibase.default_user w pliku php.ini.
- hasło
-
Hasło użytkownika . Może być ono ustawione za pomocą dyrektywy konfiguracyjnej PHP ibase.default_password w pliku php.ini.
- kodowanie_znaków
-
Parametr kodowanie_znaków jest domyślnym kodowaniem znaków narodowych w bazie danych.
- bufory
-
Parametr bufory jest liczbą buforów bazy danych jaką ma zaalokować serwer w swojej pamięci podręcznej. Jeżeli jest ustawiony na 0, lub jest pominięty, to serwer użyje wartości domyślnej.
- dialekt
-
Parametr dialekt ustawia domyślny dialekt SQL dla wszystkich instrukcji wykonywanych podczas połączenia. Domyślnie jest on ustawiony na najwyższy obsługiwany przez biblioteki klienta. Jest obsługiwany przez InterBase 6 i nowsze wersje.
- rola
-
Są obsługiwane przez InterBase 5 i nowsze wersje.
- synchronizacja
-
Zwracane wartości
Zwraca identyfikator połączenia do serwera Firebird/InterBase w przypadku powodzenia, lub FALSE w przypadku błędu.
Błędy/Wyjątki
Jeżeli są zwracane błędy takie jak "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (to może się zdarzyć w przypadku użycia niektórych znaków narodowych) po użyciu funkcji ibase_query(), to należy ustawić kodowanie znaków (np. ISO8859_2, WIN1250, UTF8).
Rejestr zmian
| Wersja | Opis |
|---|---|
| 4.0.0 | Dodano parametry bufory , dialekt i rola . |
Przykłady
Przykład #1 Przykład ibase_connect()
<?php
$host = 'localhost:/sciezka/do/mojej_bazy.fdb';
$dbh = ibase_connect($host, $username, $password, 'ISO8859_2');
$stmt = 'SELECT * FROM NAZWA_TABELI';
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
echo $row->NAZWA_KOLUMNY, "\n";
}
ibase_free_result($sth);
ibase_close($dbh);
?>
Zobacz też:
- ibase_pconnect() - Otwiera stałe połączenie do serwera Firebird/InterBase
- ibase_close() - Zamyka połączenie z serwerem Firebird/InterBase
ibase_connect
22-Jan-2008 02:25
10-Aug-2007 09:32
Remember for different locations
of php.ini file:
..\xampp\php\php.ini
..\xampp\apache\bin\php.ini
..\xampp\php\php4\php.ini
Please do not confuse this
and know location _loaded_ *.ini-file!
11-Feb-2007 11:06
ag at dividi dot de wrote:
"
The solution is to insert the line
gds_db 3050/tcp #firebird Database
into the windows services file %WINDIR%\\system32\\drivers\\etc\\services
"
...but it is very important to hit ENTER at the end of this line:
gds_db 3050/tcp #firebird Database
I spent 2 hours before I discover this - I love Windows ;-)
--
greetings
20-Sep-2005 12:07
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
05-Dec-2004 01:02
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());
$sql = "SELECT PO_NUMBER, ORDER_STATUS, ITEM_TYPE FROM SALES";
$cursor = ibase_query($sql);
$row_array = ibase_fetch_row($cursor);
print_r($row_array);
ibase_free_result($cursor);
ibase_close($db);
Also you CAN get away with the following connection string:
ibase_connect('/opt/firebird/examples/employee.fdb', 'sysdba', 'yourpass')
05-Aug-2004 11:08
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 :)
15-Jun-2003 06:22
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.id, c.title, c.description ";
$query .= "FROM collections c ";
$query .= "WHERE (c.id = $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.
eg:
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.
21-Nov-2000 03:44
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.
Anthony
