PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ibase_restore> <ibase_prepare
Last updated: Fri, 22 Aug 2008

view this page in

ibase_query

(PHP 4, PHP 5)

ibase_queryExecuta uma consulta em um banco de dados InterBase

Descrição

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

Executa uma consulta em um banco de dados InterBase.

Parâmetros

link_identifier

Um link identificador do InterBase. Se omitido, o último link é usado.

query

Uma query do InterBase.

bind_args

Valor Retornado

Se houver um erro na consulta, retorna FALSE. Se ela for bem sucedida e houver um conjunto de resultados (possivelmente vazio), como o retornado por uma consulta SELECT, retorna um identificados de resultado. Se a consulta for bem sucedida e não houver resultado, retorna TRUE.

Nota: No PHP 5.0.0 e posterior, esta função irá retornar o número de linhas afetadas pela consulta para INSERT, UPDATE e DELETE. Para manter a compatibilidade com versões anteriores, irá retornar TRUE para estas consultas se ela for bem sucedida sem afetar nenhuma linha.

Erros

Se você tiver um erro como "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (isto acontece quando você tenta usar alguns caracteres com acentos) quando você utilizar esta e depois ibase_query() você deverá definir o conjunto de caracteres (ex. ISO8859_1 ou seu conjunto de caraacteres atual).

Exemplos

Exemplo #1 Exemplo da ibase_query()

<?php

$host 
'localhost:/path/to/your.gdb';

$dbh ibase_connect($host$username$password);
$stmt 'SELECT * FROM tblname';

$sth ibase_query($dbh$stmt) or die(ibase_errmsg());

?>



ibase_restore> <ibase_prepare
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
ibase_query
apolenary at mail dot ru
31-May-2006 03:20
In woking time ibase_qury() and ibase_fetch_row() with many time call thei arise the ERROR -> Fatal error: Maximum execution time of 30 seconds exceeded

ERROR arise in that script:
foreach ($vidtr_list as $vidtr)
{
   foreach ($branches_train as $from)
   {
     foreach ($branches_train as $to)
     {
       if (isset($pricelst_train[$vidtr][$from][$to]['ID']))
       {
    for ($i = 1; $i < 7; $i++)
    {
      $id = $pricelst_train[$vidtr][$from][$to]['ID'];
               $sql_v = "SELECT * FROM P_GET_PRICE_C_VES('$id','$std_train1_ves[$i]')";
      $query_rez = ibase_query($db,$sql_v) or die(ibase_errmsg());
      $prc_v =  ibase_fetch_row($query_rez);
      $sql_o = "SELECT * FROM P_GET_PRICE_C_OBYOM('$id', '$std_train1_obyom[$i]')";
       $query_rez = ibase_query($db,$sql_o) or die(ibase_errmsg());
      $prc_o =  ibase_fetch_row($query_rez);
                   
    if (isset($prc_o[0]))
    {
    $c_obyom = $prc_o[0];
    $c_ves = $prc_v[0];
    $prices_train[$id][$i] = array( 'OBYOM' => $c_obyom,'VES'    => $c_ves );
    $mysql_jde_price[$cnt_price] = "INSERT INTO jde_price VALUES (default, '$id', '$std_train1_ves[$i]', '$c_ves', '$std_train1_obyom[$i]', '$c_obyom');";
    $cnt_price++;
    }
    }
   }
  }
 }
}

How I can decide that Error?
akach [at] exat (dot) ru
28-Jul-2005 01:18
If you use ibase_query() for SELECT without fetching result then you must know that SELECT isn't actually executed.
E.g. you perform "SELECT MY_UDF(param) from RDB$DATABASE" - MY_UDF isn't actually called until you fetch result.

This is a feature(or bug) of php interbase drivers, not interbase/firebird itself.

Test conditions: firebird 1.5.2, php 4.
escoric at latinmail dot com
17-Aug-2004 07:43
/* If your work environment is windows */

$link=ibase_connect ($path, $usuario, $password, 'WIN1251');
chrisg at cordell dot com dot au
04-Jun-2004 08:57
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;
}
?>
SenorTZ senortz at nospam dot yahoo dot com
24-Jul-2003 01:18
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 ..."
elf at royal dot net
28-Mar-2002 09:18
A BLOB can be fetched easily adding IBASE_TEXT parameter to the ibase_fetch_object() function:

$r=ibase_query("select BLOB from BLOBS where BLOB_ID=1");
$d=ibase_fetch_object($r,IBASE_TEXT);

and it will fetch the BLOB as a text. Thus it referres to it like this:
$d->BLOB

*** ELF ***
eric_cavalcanti at hotmail dot com
19-Jan-2002 09:11
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);

ibase_restore> <ibase_prepare
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites