php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23613 [INTERBASE] ibase_fetch_assoc() / ibase_fetch_object() elements case-sensitive
Submitted: 2003-05-13 12:49 UTC Modified: 2007-11-01 22:44 UTC
From: vhcampos at terra dot com dot br Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.2-RC3-dev OS: Windows 98
Private report: No CVE-ID: None
 [2003-05-13 12:49 UTC] vhcampos at terra dot com dot br
When I use the following code for the following table, PHP returns the message:

Notice: Undefined index: name in d:\sites\index.php on line 29

when I try to echo($row["name"]) (or whatever field I try).

If I try using $row->name after a $row = ibase_fetch_object($rst), I get the message:

Notice: Undefined property: name in d:\sites\index.php on line 39

The problem doesn't happen if the table is empty.

Interbase table:

CREATE TABLE "NAME" 
(
  "COD"	INTEGER NOT NULL,
  "NAME"	VARCHAR(50) CHARACTER SET WIN1252 NOT NULL,
  "DATE1"	TIMESTAMP,
 PRIMARY KEY ("COD")
);

PHP Example:

<?
  $local_bd = "intranet:D:\Database\Projetos.gdb";
  $usuario = "SYSDBA";
  $senha = "masterkey";
  $characterSet = "WIN1252";
  $cn = ibase_connect($local_bd, $usuario, $senha, $characterSet, 0, 3)
        or die("Cannot connect to database.");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>

This is just a test.
<p>

<?
  $sql = "select cod, name, date1 from Name order by name";
  $rst = ibase_query($cn, $sql);
  
  while ($row = ibase_fetch_row($rst))
  {
    echo("ID: " . $row["cod"] . "<br>\n");
	echo("Name: " . $row["name"] . "<br>\n");
  }
  
  ibase_free_result($rst);
  
  $rst = ibase_query($cn, $sql);
  
  while ($row = ibase_fetch_object($rst))
  {
    echo("ID: " . $row->cod . "<br>\n");
	echo("Name: " . $row->name . "<br>\n");
  }
  
  ibase_free_result($rst);
?>

</body>
</html>
<?
  ibase_close($cn);
?>

PS: I'm using Apache 1.3.27 for Windows, PHP 4.3.1 and Firebird 1.0.2.908 (the latest version of Firebird's 1.0 tree).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-13 12:51 UTC] vhcampos at terra dot com dot br
I forgot to mention earlier, but if I use $row[1] instead of $row["name"] the field is correctly retrieved.
 [2003-05-13 16:05 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Also, shorten your example script, we don't need HTML in it. And read the manual, ibase_fetch_row() returns numerical indices. Try doing var_dump() on the $row with both ibase_fetch_row() and ibase_fetch_object().

FYI: There's ibase_fetch_assoc() (undocumented for some reason) which returns the stuff how you expect.


 [2003-05-13 21:31 UTC] vhcampos at terra dot com dot br
You're right about ibase_fetch_row(): I should have read the manual.

As for ibase_fetch_object(), I noticed (after using var_dump()) that all returned fields are in uppercase, so the example in the manual is wrong (the "email" field in the example should be "EMAIL"). Couldn't it be case insensitive since all fields in Interbase/Firebird are converted to  uppercase?
 [2003-05-13 23:15 UTC] vhcampos at terra dot com dot br
I changed my code to use ibase_fetch_assoc() instead of ibase_fetch_row() to get an associative array. Surprisingly all field names are case-sensitive, like ibase_fetch_object()'s properties, mentioned in a prior message. I believe this behavior is incorrect, those values should be case-insensitive.

I tried this using Apache 1.3.27 for Windows, Firebird 1.0.2.908 and PHP versions 4.3.1 and 4.3.2-RC3-dev.
 [2007-11-01 22:44 UTC] lwe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

According to the Interbase/Firebird documentation, columns are case-sensitive, when declared using double qoutes, as you have done in your create table example.
And you are forced to use double qoutes around every column-name in sql statements.
ibase_fetch_object returns case-sensitive property names.

If you declare the columns without double qoutes, the names are case-insensitive in SQL statements (and you write them without double quotes).
ibase_fetch_object returns uppercase property names.

So actually this isn't a bug in PHP, but merely the design of Interbase/Firebird.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC