0

I'm trying to query a datasource using a simple SQL query, but I'm getting the following error: *Warning: odbc_exec() [function.odbc-exec]: SQL error: [SimbaLNA][Simba][SimbaEngine ODBC Driver]select (<< ??? >>[agent_id], [agent_name]) from agent;, SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\Tas\showtables.php on line 22*

I know my ODBC connection is established and connecting correctly because I'm able to execute the following code and receive a list of all the table names.:

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

When I proceed and try and execute the below code:

/* 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

I get the error stated above. Does anyone know why this would be happening?

If any more information is required, just let me know.

Many thanks in advance

Kahlil N
  • 71
  • 2
  • 10
  • 37000 is the ODBC 2 status code now 42000 in ODBC 3. It means "Syntax error or access violation". The error text contains << ??? >> which suggests this is where the SQL error is located, however the syntax looks ok to me. I'd double check the code you've pasted in this node is exactly what you are using and especially that SQL text for the select it is objecting to. You also might find this document on ODBC errors useful (http://www.easysoft.com/developer/interfaces/odbc/diagnostics_error_status_codes.html) and in particular the 2 appendices. – bohica Sep 05 '12 at 09:50
  • You are exactly right, thank you. There is no error in the code I posted, but there was in my actual code. I didn't notice it until you mentioned it. Thanks for the link, it's going to be useful to me. – Kahlil N Sep 05 '12 at 14:07

0 Answers0