英文:
cannot get data of column #id
问题
I want to echo some values of a query
while(odbc_fetch_row($tableX))
{
for($i=1;$i<=odbc_num_fields($tableX);$i++)
{
if ($i==1)
{
echo odbc_result($tableX,1); //echoed
echo odbc_result($tableX,2); //echoed
echo odbc_result($tableX,21); //echoed
echo odbc_result($tableX,22); //echoed
var_dump(odbc_result($tableX,22)); //returns values
}
else if($i==2)
{
echo odbc_result($tableX,$i).'++';
var_dump(odbc_result($tableX,22)); //returns bool(false) and empty rows
}
else if($i==3)
{
echo odbc_result($tableX,$i).'+';
}
else
{
echo odbc_result($tableX,$i); //($tableX,1) ($tableX,2) ($tableX,3) echoed ($tableX,21) ($tableX,22) not echoed
}
}
}
As I indicated in the comments, some of the odbc_result's raises an error:
cannot get data of column #21
cannot get data of column #22
I (am not sure but) think the issue is:
An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried.
Yet, I couldn't see the reason.
Thanks in advance.
Edit: Else works if I delete the echoes under if ($i==1)
Both 21 & 22's data type is NCLOB
英文:
I want to echo some values of a query
while(odbc_fetch_row($tableX))
{
for($i=1;$i<=odbc_num_fields($tableX);$i++)
{
if ($i==1)
{
echo odbc_result($tableX,1); //echoed
echo odbc_result($tableX,2); //echoed
echo odbc_result($tableX,21); //echoed
echo odbc_result($tableX,22); //echoed
var_dump(odbc_result($tableX,22)); //returns values
}
else if($i==2)
{
echo odbc_result($tableX,$i).'++';
var_dump(odbc_result($tableX,22)); //returns bool(false) and empty rows
}
else if($i==3)
{
echo odbc_result($tableX,$i).'+';
}
else
{
echo odbc_result($tableX,$i); //($tableX,1) ($tableX,2) ($tableX,3) echoed ($tableX,21) ($tableX,22) not echoed
}
}
}
As I indicated in the comments, some of the odbc_result's raises an error:
> cannot get data of column #21
> cannot get data of column #22
I (am not sure but) think the issue is:
> An error occurs if a column number parameter for a field is less than
> one or exceeds the number of columns (or fields) in the current
> record. Similarly, an error occurs if a field with a name that is not
> one of the fieldnames of the table(s) that is(are) being queried.
Yet, I couldn't see the reason.
Thanks in advance.
Edit: Else works if I delete the echoes under if ($i==1)
Both 21 & 22's data type is NCLOB
答案1
得分: 1
将NCLOBs (odbc_result($tableX,21) and odbc_result($tableX,22))
转换为nvarchar
CAST(BINTOSTR(CAST("COLUMNNAME" AS binary)) as nvarchar)
英文:
Fixed it by converting NCLOBs (odbc_result($tableX,21) and odbc_result($tableX,22))
to nvarchar
CAST(BINTOSTR(CAST("COLUMNNAME" AS binary)) as nvarchar)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论