php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16777 Multiple odbc connections failing
Submitted: 2002-04-23 19:52 UTC Modified: 2002-05-02 14:48 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jarod dot ferguson at eds dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.2.0 OS: win 2000
Private report: No CVE-ID: None
 [2002-04-23 19:52 UTC] jarod dot ferguson at eds dot com
I would like to apologize, for I have uninstalled 4.2 from my server and went back to 4.1, and now I do not have the complete error messages.

Server: Windows 2000 IIS
SQL server 2k
PHP ver 4.2
odbc 

Problem: Old scripts that ran fine on version 4.1.2 now give error messages stating that the odbc connection is in use "SQLstate S1000 waiting for result from previous hstmnt"

We have scoured the INI, tried the old ini as well. same results. I put 4.1.2 back on, issue is gone. 

I am running into this issue when looping through the Db and running a subloop inside based off results from the first loop. I do this with functions inside a loop as well as actually running a new while loop inside of the first one. I have tried altering my code, making sure i have closed all db connections (which i never do) and free allodbc results from memory.

sample codes:

here are the defined functions:
function countapproved ($project_id){
	$time = date ("H:i");
	$date = date("m/d/y");
	$cto_f = odbc_connect("emp1","","")
	 or die("Error Connecting To CDBMS.");
	$cnt_rec = ("select count (*) from [cto_main] where emp_pro ='$project_id' and date = '$date' and pref_time < '$time' and cto_status_id <> '2' and cto_status_id <> '3' and (shift_time > '$time')");
	$ex_cr = odbc_exec($cto_f,$cnt_rec);
	$count = odbc_result($ex_cr, 1);
	return $count;
}

function countgranted ($project_id){
	$time = date ("H:i");
	$date = date("m/d/y");
	$cto_f = odbc_connect("emp1","","")
	 or die("Error Connecting To CDBMS.");
	$cnt_rec = ("select count (*) from [cto_main] where emp_pro ='$project_id' and date = '$date' and cto_status_id = '2'");
	$ex_cr = odbc_exec($cto_f,$cnt_rec);
	$count = odbc_result($ex_cr, 1);
	return $count;
}

function countsignedout ($project_id){
	$time = date ("H:i");
	$date = date("m/d/y");
	$cto_f = odbc_connect("emp1","","")
	 or die("Error Connecting To CDBMS.");
	$cnt_rec = ("select count (*) from [cto_main] where (emp_pro ='$project_id') and (date = '$date') and cto_status_id = '3'");
	$ex_cr = odbc_exec($cto_f,$cnt_rec);
	$count = odbc_result($ex_cr, 1);
	return $count;
}

function countpending ($project_id){
	$time = date ("H:i");
	$date = date("m/d/y");
	$cto_f = odbc_connect("emp1","","")
	 or die("Error Connecting To CDBMS.");
	$cnt_rec = ("select count (*) from [cto_main] where emp_pro ='$project_id' and date = '$date' and pref_time > '$time' and cto_status_id <> '2' and cto_status_id <> '3' and (shift_time > '$time')");
	$ex_cr = odbc_exec($cto_f,$cnt_rec);
	$count = odbc_result($ex_cr, 1);
	return $count;
}

running inside this loop:



$get_cto_pro= ("SELECT     *, project.project_name FROM cto_project INNER JOIN project ON cto_project.cto_project_id = project.project_id order by project_name");
				$ex_cp = odbc_exec($cto,$get_cto_pro);
				$row = 0;
					while( odbc_fetch_row( $ex_cp ) ) { 
						 $row++;
						 $p_name= odbc_result( $ex_cp, 'project_name' );
						 $project_id= odbc_result( $ex_cp, 'cto_project_id' );
						
						 $total_appr = countapproved ($project_id);
						 $total_granted = countgranted ($project_id);
						 $total_s_o = countsignedout ($project_id);
						 $total_pend = countpending ($project_id);
						 
						 $total = $total_appr + $total_granted + $total_s_o + $total_pend;
						
						 print ("<tr><td><a href=\"queue.php?p_name=$p_name&project_id=$project_id\">$p_name</td><td bgcolor=ffffff><center>$total</center></td><td bgcolor=ffffff><center>$total_appr</center></td><td bgcolor=ffffff><center>$total_pend</center></td><td bgcolor=ffffff><center>$total_granted</center></td><td bgcolor=ffffff><center>$total_s_o</center></td></tr>");


I may just be doing something wrong, but I have had very good performance untill now. Any feedback would be appreciative.
Thanks.

Jarod Ferguson						

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-24 18:48 UTC] kalowsky@php.net
Can you please provide a simplified test case that doesn't work for you?
 [2002-04-30 03:59 UTC] tache2 at xnet dot ro
a simplified example would be :

$res=odbc_exec($conn,"select * from categorii order by ordine_categorie");
for($i=1;odbc_fetch_row($res);$i++)
	{
	$res2=odbc_exec($conn,"select * from subcategorii where id_categorie=$idcateg order by ordine_subcategorie");
	......
      }

the second query fails but ONLY when the first return more than one row. i tried with different connections but doesn't work.

check my original post at http://news.php.net/article.php?group=php.db&article=18880
 [2002-04-30 10:56 UTC] jarod dot ferguson at eds dot com
OK, simple version:
$var = odbc_exec($cnx,Some query);
$row = 0;
while (odbc_fetch_row($var)){
     $row++;
     $res1 = odbc_fetch_row($var, 1 );
     $res2 = odbc_fetch_row($var, 2 );

          $var2 = odbc_exec($cnx,Select * from some table 
             where field = $res1);
             while (odbc_fetch_row($var2)){
             $row++;
             $res3 = odbc_fetch_row($var2, 1 );
             $res4 = odbc_fetch_row($var2, 2 );
        }
}
 [2002-05-01 08:41 UTC] kalowsky@php.net
I believe this is fixed in CVS.  Please try one of the latest CVS snapshots, and see if it solves the problem for you.  If not, reopen the bug... 
 [2002-05-02 12:23 UTC] josh at engledental dot com
I am having this problem as well.  The cursor seems to be using the default "forward-only" mode.  I assume PHP 4.1 automatically generated a static cursor and 4.2 is not?

Any ideas?  This totally screws up the web application I'm working on.
 [2002-05-02 14:48 UTC] kalowsky@php.net
please try a snapshot, or wait until 4.2.1
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 19:01:32 2025 UTC