#23613 [Opn->Fbk]: PHP sometimes cannot display fields by name, only by position
| From: | sniper@php.net | Date: | Tue, 13 May 2003 21:05:31 +0000 |
| Subject: | #23613 [Opn->Fbk]: PHP sometimes cannot display fields by name, only by position | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-39558@lists.php.net to get a copy of this message | ||
ID: 23613
Updated by: sniper@php.net
Reported By: vhcampos at terra dot com dot br
-Status: Open
+Status: Feedback
Bug Type: InterBase related
Operating System: Windows 98
PHP Version: 4.3.1
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2003-05-13 12:51:11] 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 12:49:13] 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).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23613&edit=1