By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

do...while loops forever

P: n/a
While attempting to alleviate a persistent but not consistent problem
with my database operation (DB2) I coded the do...while loop around my
odbc_connect. When $dbConn is false the first time, the program never
returns. This problem repeatable with or without the @ on the
odbc_connect call. I would someone pointing out my stupidity. I did
RTFM, including the examples, and was no further enlightened. Thanks in
advance.

function conn() {
global $schema, $database;
$schema = "is3";
$database = "animalst";
$dbuser = "db2inst1";
$dbpwd = "db2rules";
$ct = 0;
do {
$dbConn = odbc_connect($database,$dbuser,$dbpwd);
$ct += 1;
if($dbConn==False) { sleep(1); }
}
while(($dbConn==False) && ($ct<5)) ;
if ( $dbConn==False) {
printf("<br>The odbc_connect parameters were:[%s] [%s]
[%s]<br>\n" , $database,$dbuser,$dbpwd);
printf("<br>Tried %d times<br>\n",$ct);
showerror();
die("could not connect to $database");
}
return $dbConn;
}
?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Robert Stearns wrote:
While attempting to alleviate a persistent but not consistent problem
with my database operation (DB2) I coded the do...while loop around my
odbc_connect. When $dbConn is false the first time, the program never
returns. This problem repeatable with or without the @ on the
odbc_connect call. I would someone pointing out my stupidity. I did
RTFM, including the examples, and was no further enlightened. Thanks
in advance.


This might work out better (although I must point out that you should fix
your database if you really need a routine like this):

while (!($dbConn = odbc_connect($database,$dbuser,$dbpwd)) &&
(++$cnt < 5)) {
sleep(1);
}
JW

Jul 17 '05 #2

P: n/a
"Robert Stearns" <rs**********@charter.net> wrote in message
news:10*************@corp.supernews.com...
While attempting to alleviate a persistent but not consistent problem
with my database operation (DB2) I coded the do...while loop around my
odbc_connect. When $dbConn is false the first time, the program never
returns. This problem repeatable with or without the @ on the
odbc_connect call. I would someone pointing out my stupidity. I did
RTFM, including the examples, and was no further enlightened. Thanks in
advance.

function conn() {
global $schema, $database;
$schema = "is3";
$database = "animalst";
$dbuser = "db2inst1";
$dbpwd = "db2rules";
$ct = 0;
do {
$dbConn = odbc_connect($database,$dbuser,$dbpwd);
$ct += 1;
if($dbConn==False) { sleep(1); }
}
while(($dbConn==False) && ($ct<5)) ;
if ( $dbConn==False) {
printf("<br>The odbc_connect parameters were:[%s] [%s]
[%s]<br>\n" , $database,$dbuser,$dbpwd);
printf("<br>Tried %d times<br>\n",$ct);
showerror();
die("could not connect to $database");
}
return $dbConn;
}
?


As far as I can tell nothing in the PHP code should cause the loop to go
forever. Looks more like a ODBC driver issue to me. The driver must have
acquired some DB2 resouces before it failed, so that when you call
odbc_connect the second time, it deadlocks.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.