使用PHP通过ODBC查询数据源

时间:2012-09-05 03:50:23

标签: php sql odbc totalview

我正在尝试使用简单的SQL查询查询数据源,但是我收到以下错误:*警告:odbc_exec()[function.odbc-exec]:SQL错误:[SimbaLNA] [Simba] [ SimbaEngine ODBC Driver]从代理商中选择(<<< ???>> [agent_id],[agent_name]),在第22行的C:\ xampp \ htdocs \ Tas \ showtables.php中的SQLExecDirect中的SQL状态37000 *

我知道我的ODBC连接已建立并正确连接,因为我能够执行以下代码并接收所有表名的列表。:

if (!$conn) {
 {exit("Connection Failed: " . $conn);}
}
$result = odbc_tables($conn);
$tables = array();
while (odbc_fetch_row($result)){
  if(odbc_result($result,"TABLE_TYPE")=="TABLE") {
    echo"<br>".odbc_result($result,"TABLE_NAME");
  }//end if
}//end while

当我继续并尝试执行以下代码时:

/* Fetch The Fieldnames into an Array */
if($result = odbc_exec($conn,"SELECT agent_id, agent_name FROM agent")) {
  for($i = 1;$i <= odbc_num_fields($result);$i++) {
    $odbc['rows']['fields'][$i] = odbc_field_name($result,$i);
  } //end for
  unset($i);
  odbc_free_result($result);
}//end if
else {
  exit("Error in SQL Query");
}//end else

我收到上述错误。有谁知道为什么会发生这种情况?

如果需要更多信息,请告诉我。

非常感谢提前

0 个答案:

没有答案