(PHP 5)

ibase_query Führt eine Abfrage (Query) auf eine InterBase-DB aus


int ibase_query ([ int $link_identifier ], string $query [, int $bind_args ] )

Erzeugt eine Anfrage auf eine InterBase-DB, deren Ergebnis mit ibase_fetch_row(), ibase_fetch_object(), ibase_free_result() und ibase_free_query() weiter verarbeitet werden kann.


Obwohl diese Funktion auch die Verwendung von Platzhaltern unterstützt, ist ihr keine besondere Bedeutung beizumessen. Für reale Abfragen und Beispiele sehen sie unter ibase_prepare() und ibase_execute() nach.

add a note add a note

User Contributed Notes 4 notes

escoric at latinmail dot com
9 years ago
/* If your work environment is windows */

$link=ibase_connect ($path, $usuario, $password, 'WIN1251');
chrisg at cordell dot com dot au
9 years ago
Simple function to retrieve the results of an SQL statement into an array, will also cater for BLOB fields:

function interbase_sql_exec ($sql) {
$dataArr = array();
$host = "svrname:path\filename.GDB";
$username = "whatever";
$password = "******";
$connection = ibase_connect ($host, $username, $password,'ISO8859_1', '100', '1');
$rid = @ibase_query ($connection, $sql);
    if (
$rid===false) errorHandle(ibase_errmsg(),$sql);
$coln = ibase_num_fields($rid);
$blobFields = array();
    for (
$i=0; $i < $coln; $i++) {
$col_info = ibase_field_info($rid, $i);
        if (
$col_info["type"]=="BLOB") $blobFields[$i] = $col_info["name"];
    while (
$row = ibase_fetch_row ($rid)) {
        foreach (
$blobFields as $field_num=>$field_name) {
$blobid = ibase_blob_open($row[$field_num]);
$row[$field_num] = ibase_blob_get($blobid,102400);
$dataArr[] = $row;
ibase_close ($connection);
SenorTZ senortz at nospam dot yahoo dot com
10 years ago
Two comments on interogating system tables in Interbase or Firebird; I hope it helps.

1. if you try to build a query string to extract data from a system table (that has the form "rdb$some_name"), you should divide the "rdb$some_name" table name in your query string using the string merge operator ".".
$query = "select rdb"."$"."relation_name as TABLE_NAME from rdb"."$"."relations where rdb"."$"."system_flag=0";

2. The second thing is related to the fact that you can later use (after the call to ibase_fetch_object) as field identifier the ALIAS used in the query for the "rdb$some_name" table.

$get_table_names_query = "select rdb"."$"."relation_name as TABLE_NAME from rdb"."$"."relations where rdb"."$"."system_flag=0";
$res_table_names_query = ibase_query($dbconnection, $get_table_names_query);
while ($row_table_names = ibase_fetch_object($res_table_names_query))
    print($row_table_names->TABLE_NAME);//alias used

Editor's note:
it is easier to use a backslash to protect the $-sign.
eg. "select rdb\$relation_name as TABLE_NAME from ..."
eric_cavalcanti at hotmail dot com
12 years ago
Using BLOB

Insert BLOB:

 /* create blob */
$blob_id = ibase_blob_create();

 /* fill blob */
ibase_blob_add($blob_id, $var_datablob);

/* close new blob */
$blob_id_str = ibase_blob_close($blob_id);

/* insert into table  */
ibase_query("INSERT INTO BLOB_TABLE (ID, BLOB) VALUES (1, ?)",$blob_id_str);

Open BLOB:

/* query */
$set = ibase_query("SELECT BLOB FROM BLOB_TABLE WHERE ID = 1");

/* fetche a row */
$row = ibase_fetch_object($set);

/* open BLOB for read */
$blob_id = ibase_blob_open($row->BLOB);

/* get BLOB data */
$stringBLOB = ibase_blob_get($blob_id);

/* print BLOB */
echo $stringBLOB;

/* close new blob */

/* free result */
To Top