Re: Weird Problem

From: Date: Tue, 27 Feb 2001 00:49:17 +0000
Subject: Re: Weird Problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41773@lists.php.net to get a copy of this message
On Tue, 27 Feb 2001 05:53, Steve Segarra wrote: > Hi everyone, > First, let me explain I am a very knowledgable php developer. I'm not > someone trying to write their first script. I have been working on a > very large and complex problem for some time now when it suddenly > stopped working. I did not change anything in any configurations or > edit any code that would have affected how my database functionality > class would function. But, all of my connections started to bomb out. > > Follows are the entire contents of a file simp.php (minus the line > numbers): > > 1 <? > 2 > 3 $db = mysql_connect("localhost", "web", "pw") || print > "error > connecting ".mysql_error()." ".mysql_errno(); > 4 mysql_select_db("surveys"); > 5 > 6 $result = mysql_query("select * from attract") || print "error > querying ".mysql_error()." ".mysql_errno(); > 7 > 8 $i = 0; > 9 while ($row = mysql_fetch_array(mysql_query("select * from > attract"))){ // && ($i++ < 5)){ > 10 echo $row[0]." ".$row[1]."<br>"; > 11 } > 12 ?> > > > Please note that the user web@localhost identified by pw has > permissions to select from the table attract. > > Here is what I have identified so far: > > A - If I use $result in mysql_fetch_array() line 9, I get the error: > Warning: Supplied argument is not a valid MySQL result resource > in simp.php3 on line 9 > > But if I use the statement mysql_query("select * from attract") > in its > place, the loop (although infinite) will produce expected results, ie > print out the first and second columns of the first row of the table > infinitely. So basically, I would conclude the life of the variable > result is terminiating before I can use it. Why, I don't have a clue. > > B - Being tired of an infinite loop in my investigation, I added line 8 > and I placed the statement && ($i++ < 5) inside the while loop > condition. Now, only the <br> and spaces from line 10 will print, not > the actual values of the $row array. The output is <br> <br> <br> <br> > <br>, with no values from the table attract. > > This is where I stand now, completely flabberghasted and nearly insane. > Can anyone shed any light on this before I have to commit to bringing > down the webserver while I reinstall php4. (oh, btw I am running > Apache/1.3.14 (Unix) PHP/4.0.4pl1 on Red Hat 6.2 (I hate redhat, but > the bossman says its better supported than slakware. bah.)) > > Thank you all for your help. > steve Is it possible that the || construct doesn't work in the way you are using it and thus you aren't seeing mysql_error? The most common examples I have seen use the actual string 'or'. Try with a query that you _know_ will trip an error. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#41773) next »