[freetds] Multiple queries

Raymundo Perez roskiy at gmail.com
Fri May 16 03:00:31 EDT 2008

Using Linux ubuntu; apache2;PHP; unix-ODBC;

I recursively call function that create an odbc connection via FreeTDS driver
after function recursively call itself i receive following error:
*Warning*: odbc_exec() [function.odbc-exec
<https://inside.oceanrock-dr.com/function.odbc-exec>]: SQL error:
????., SQL state 00000 in SQLExecDirect in */var/www/scriptname.php*
as i understood new connection is not being created on odbc_connect
call but old connection and cursor is reused. proved it adding
odbc_close_all(); statement in the begining of the function
tried same script runing on windows OS System using native Microsfot
SQL drivers for ODBC and script worked fine

2 include_once('ps.php'); //just setting up constants
connection_string, db_user, db_pass
4 function DoNode($parent = 0)
5 {
6 $sql="Select field1,field2,field3 from table1 where somefield=$parent";
7 $conn = odbc_connect( connection_string, db_user, db_pass, SQL_CUR_USE_ODBC);
8 $result=odbc_exec($conn, $sql) or die (odbc_errormsg().'<br />'.$sql);
9 while (odbc_fetch_row($result))
10 {
11 if (odbc_result($result,'CallString')=='#')
12 $res.='<li>'.odbc_result($result,'field1').'<ul>'.DoNode(odbc_result($result,'field2')).'</ul></li>';
// <- NOTE recursive call here
13 else
14 $res.='<li><a
15 }
16 //end of function
17 return $res;
18 }
19 echo DoNode();
20 ?>

More information about the FreeTDS mailing list