使用ODBC提取数据失败,PHP中的结果为空? [英] Fetching data with ODBC failed with empty result in PHP?

查看:224
本文介绍了使用ODBC提取数据失败,PHP中的结果为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接并执行了查询,没有抛出任何异常.但是我尝试获取行以在表中显示数据,并且在我的foreach上抛出了异常.
这是我的代码:

I connected and executed query without throwing any exception. But I tried fetching rows to display the data in a table and an exception was thrown at my foreach.
Here is my code:

$con = odbc_connect("My DSN","","");
$result = odbc_exec($con,"My query");
if($result)
{
  echo "<table align=center>";
  while($row=odbc_fetch_array($result))
  {
    echo "<tr>";
    foreach($row as $r)
       echo "<td>$r</td>";
    echo "</tr>";
  }
echo "</table>";
odbc_close($con);
}


它说我使用了一个变量($ row),该变量无法用foreach进行迭代.
我已经将上面的代码与mysql,mssql一起使用,并且它们工作正常,但odbc给了我该错误,请记住我已成功连接并查询,它按我说的在foreach语句中报告了错误行,这太奇怪了,尝试使用odbc_result仅获取1个单元格,它没有引发异常,但结果为空.
您能给我一些理由吗?
您的任何帮助将不胜感激!


It said that I used a variable ($row) which couldn''t be iterated with foreach.
I have used the above code with mysql, mssql and they worked fine but odbc gave me that error, please remember that I connected and queried successfully, it reported the error line at the foreach statement as I said, it was so strange, and I have tried with odbc_result to fetch only 1 cell, it didn''t throw exception but the result was empty.
Could you please give me some reason elaborating on this?
Any of your help would be appreciated!
Thanks!

推荐答案

con = odbc_connect("My DSN",",");
con = odbc_connect("My DSN","","");


result = odbc_exec(
result = odbc_exec(


con,我的查询"); if(
con,"My query"); if(


这篇关于使用ODBC提取数据失败,PHP中的结果为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆