无法获取列 #id 的数据。

huangapple go评论61阅读模式
英文:

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&lt;=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).&#39;++&#39;;
      var_dump(odbc_result($tableX,22)); //returns bool(false) and empty rows	  
	}  
	else if($i==3)
	{
	  echo odbc_result($tableX,$i).&#39;+&#39;;	  
	} 
	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(&quot;COLUMNNAME&quot; AS binary)) as nvarchar)

huangapple
  • 本文由 发表于 2023年4月13日 19:50:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定