I'm successfully connecting to the database, and successfully pulling data and displaying it using db2_fetch_array and db2_fetch_both. The code below works just fine
$file="m03slsd0";
$file=db2_escape_string($file);
$query="SELECT slgrpn,slfrkn,slftyp,slfsze,slpqty,slpwht,slentp,slkplt FROM HUTALIB.$file";
$quepre=db2_prepare($conn,$query);
$quexe=db2_execute($quepre);
while($row=db2_fetch_both($quepre))
{
$det=$row[0];
if($det!='')
{
printf($det."</br>");
}
}
The problem comes up when i'm changing the index to column name in db2_fetch_assoc() or db2_fetch_array() - the code below prints nothing.
while($row=db2_fetch_both($quepre))
{
$det=$row['slgrpn'];
if($det!='')
{
printf($det."</br>");
}
}
Any suggestions?
Thanks in advance
Array ( [SLGRPN] => 12626 ...
Array keys are case sensitive you you will need to use
$det=$row['SLGRPN'];
not sure why the field names get turned into uppercase - it might be a characteristic of db2.
DB2 identifiers are case-insensitive by default, and will use/return uppercase field names, unless your columns are defined within double quotes (same applies for table names):
CREATE TABLE foo ( bar integer, "baz" integer );
Querying this table:
SELECT bar, "baz" FROM foo;
... in PHP would return something like:
Array (
[BAR] => something
[baz] => something
)
So you'd have to do:
echo $array['BAR'];
echo $array['baz'];
To remove any ambiguity, you can change your queries:
SELECT BAR FROM FOO;
...or define all fields and table names with double quotes:
SELECT "bar", "baz" FROM "foo"