ibase_query

(PHP 5, PHP 7 < 7.4.0)

ibase_queryEjecutar una consulta en una base de datos InterBase

Descripción

ibase_query(resource $link_identifier = ?, string $query, int $bind_args = ?): resource

Realiza una consulta sobre una base de datos InterBase.

Parámetros

link_identifier

Un identificador de enlace InterBase. Si se omite, se asume el último enlace abierto.

query

Una consulta InterBase.

bind_args

Valores devueltos

Si la consulta genera un error, se devuelve false. Si tiene éxito y existe un conjunto de resultados (posiblemente vacío), tal como ocurre con una consulta SELECT, se devuelve el identificador de resultado. Si la consulta fue exitosa y no hay resultados, se devuelve true.

Nota:

En PHP 5.0.0 y versiones posteriores, esta función devuelve el número de filas afectadas por la consulta para sentencias INSERT, UPDATE y DELETE. Con el propósito de mantener compatibilidad hacia atrás, devolverá true para estas sentencias si la consulta tuvo éxito sin afectar filas.

Errores/Excepciones

Si obtiene un error del tipo "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (esto ocurre cuando intenta usar algún caracter con acentos) cuando usa esta extensión después de llamar ibase_query(), debe definir el juego de caracteres (puede ser ISO8859_1 o su juego de caracteres actual).

Historial de cambios

Versión Descripción
5.3.1 Si no hay rows afectados, la función ahora devuelve true en caso de éxito, donde anteriormente devolvía 0 (un cero seguido por un espacio en blanco).

Ejemplos

Ejemplo #1 Ejemplo de ibase_query()

<?php

$host 
'localhost:/ruta/a/su/base_de_datos.gdb';

$gestor_bd ibase_connect($host$nombre_usuario$contrasenya);
$sent 'SELECT * FROM nombre_tabla';

$gestor_sent ibase_query($gestor_bd$sent) or die(ibase_errmsg());

?>

Ver también

add a note add a note

User Contributed Notes 5 notes

up
5
chrisg at cordell dot com dot au
19 years ago
Simple function to retrieve the results of an SQL statement into an array, will also cater for BLOB fields:

<?php
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);
           
ibase_blob_close($blobid);
        }
       
$dataArr[] = $row;
    }
   
ibase_close ($connection);
    return
$dataArr;
}
?>
up
1
escoric at latinmail dot com
19 years ago
/* If your work environment is windows */

$link=ibase_connect ($path, $usuario, $password, 'WIN1251');
up
0
eric_cavalcanti at hotmail dot com
22 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 */
ibase_blob_close($blob_id);

/* free result */
ibase_free_result($set);
up
-1
SenorTZ senortz at nospam dot yahoo dot com
20 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.

Example:
$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 ..."
up
-2
coladict at gmail dot com
8 years ago
Contrary to it's description, the function does not always execute the query, unless you try fetching the results. I discovered this through the following code:

<?php
                $result
= ibase_query($dbh,"SELECT boniid FROM PROC_INS_OBONI_DELIV_ADDBONITM ( ? , ? , ? , ? , null , ? )", $bon_id , $plucode2 , $amount , $note $discount);
               
$this->log_add(mb_convert_encoding("SELECT boniid FROM PROC_INS_OBONI_DELIV_ADDBONITM ( " . $bon_id . ", " . $plucode2 . ", " . $amount . ", " . $note . ", " . $nullparent . ", " . $discount . " )",'utf8','cp1251'));

                if (!
$result){
                   
$errmsg = ibase_errmsg();
                   
ibase_rollback($dbh);
                   
ibase_close($dbh);

                   
$this->log_add("Item (" . $mid . " - " . $plucode2 . ") : Error returned (" . __LINE__ . "): " . $errmsg);
                    return
"Error sending product ( $m_name). Error message:  $errmsg";
                }

               
// item data does NOT enter the database if I don't call ibase_fetch_assoc
               
$row = ibase_fetch_assoc($result);
?>

This problem may be limited to FireBird 1.5 or it may not be. Either way, be wary of it.
To Top