<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Oops! I should have said I'm using mysql PDOs.</DIV>
<DIV>anyways after a read thru the manual heres what I found.</DIV>
<DIV> </DIV>
<DIV>"$conn" returns a PDO object<BR>"$conn->query($sql)" returns a PDOStatement Object<BR>"$query($sql)" returns an array</DIV>
<DIV> </DIV>
<DIV>since the last line returns an array the $conn object should be iterable.</DIV>
<DIV> </DIV>
<DIV>Moreover, I have also tested it without a database service for A.php. I removed all db handling code from A.php and am able to login. I have no problem. thats because the dbconnect object is already created by login2.php and its just once. So I am able to login because A.php doesnt include dbconnect.php(just for the test). The problem kicks in when A.php locally includes dbconnect.php. Thats when there is a confiict of object creation. first login2.php creates the object (obviously by doing a $conn = dbConnect('query'); new PDO blah blah..) and then the local script A.php has its own include to dbconnect.php.</DIV>
<DIV> </DIV>
<DIV>So I can say after testing that the code is fine when the includes are switched off.</DIV>
<DIV> </DIV>
<DIV>I also tried persistent connections by adding another argument in the new PDO constructor</DIV>
<DIV>array(PDO::ATTR_PERSISTENT => true); and then making all $conn=null on completion of each local script, but that didnt seem to work either....probably I was missing something else, but I cut the research since I thought I was going away in a tangent.</DIV>
<DIV> </DIV>
<DIV>have anyone struck gold yet?</DIV>
<DIV> </DIV>
<DIV>thanks</DIV>
<DIV>greymatter</DIV>
<DIV><FONT face=Consolas color=#0000bb></FONT><BR><BR>--- On <B>Mon, 22/2/10, Kim Richardson <I><krichardson@viewdale.com.au></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid"><BR>From: Kim Richardson <krichardson@viewdale.com.au><BR>Subject: Re: [PHPwestoz] problem with includes<BR>To: phpwestoz@lists.linux.org.au<BR>Date: Monday, 22 February, 2010, 15:27<BR><BR>
<DIV id=yiv230644107>The output of $conn->query($sql) would be a result set pointer, not an actual array. <BR><BR>Try <BR><BR>$result=$conn->query($sql);<BR>if($result->num_rows>0)<BR>{<BR> while($row=$result->fetch_assoc())<BR> {<BR> ... do your magic here<BR> }<BR>}<BR><BR>On 22/02/2010 9:58 PM, Gnitnop G wrote:
<BLOCKQUOTE type="cite">
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD style="FONT-FAMILY: inherit; font-size-adjust: inherit; font-stretch: inherit" vAlign=top>
<DIV>30 <div id="artdescription"><BR> <?php<BR> foreach ($conn->query($sql) as $row) {<BR> ?><BR> <h2><?php echo $row['title']; ?></h2><BR> <p><?php $extract = getFirst($row['article']); <BR> echo $extract[0];<BR> if ($extract[1]) {<BR> <BR> echo '<a href="abstractexplanation.php?article_id='.$row['article_id'].'"> More</a>';<BR> }
?></p><BR> <?php } ?><BR>41 </div></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>ps: according to my sketched-out example, that last error should look like this:</DIV>
<DIV> </DIV>
<DIV>[Mon Feb 22 12:26:49 2010] [error] [client 127.0.0.1] PHP Warning: Invalid argument supplied for foreach() in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\xxxxxxxx\\B.php on line 31, referer: <A href="http://localhost/xxxxxxxx/B.php" target=_blank rel=nofollow>http://localhost/xxxxxxxx/B.php</A></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>--- On <B>Mon, 22/2/10, Keith Moss <I><A class=moz-txt-link-rfc2396E href="http://uk.mc246.mail.yahoo.com/mc/compose?to=khan@swcombine.com" target=_blank rel=nofollow ymailto="mailto:khan@swcombine.com"><khan@swcombine.com></A></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid"><BR>From: Keith Moss <A class=moz-txt-link-rfc2396E href="http://uk.mc246.mail.yahoo.com/mc/compose?to=khan@swcombine.com" target=_blank rel=nofollow ymailto="mailto:khan@swcombine.com"><khan@swcombine.com></A><BR>Subject: Re: [PHPwestoz] problem with includes<BR>To: "PHP users in Western Australia (or nearby)" <A class=moz-txt-link-rfc2396E href="http://uk.mc246.mail.yahoo.com/mc/compose?to=phpwestoz@lists.linux.org.au" target=_blank rel=nofollow ymailto="mailto:phpwestoz@lists.linux.org.au"><phpwestoz@lists.linux.org.au></A><BR>Date: Monday, 22 February, 2010, 11:32<BR><BR>
<DIV id=yiv974069415>Ah I see it's time once again for the annual post to the mailing list :)
<DIV><BR></DIV>
<DIV>include_once should indeed work the situation you describe.</DIV>
<DIV><BR></DIV>
<DIV>What was the code around line 31 of journal_pdo.php that was throwing the foreach error?<BR><BR>
<DIV class=gmail_quote>On 22 February 2010 13:30, Gnitnop G <SPAN dir=ltr><<A href="http://uk.mc246.mail.yahoo.com/mc/compose?to=gnitnop@ymail.com" target=_blank rel=nofollow>gnitnop@ymail.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=top>
<DIV> </DIV>
<DIV>Hi All!</DIV>
<DIV> </DIV>
<DIV>I seem to be having a problem with php includes. sketching out my problem with an example will look something like this:</DIV>
<DIV> </DIV>
<DIV>I have 3 main php pages A.php, B.php and C.php.</DIV>
<DIV>I have 3 include files; (1) dbconnect.php, (2) login1.php (3) login2.php</DIV>
<DIV> </DIV>
<DIV>All main pages; A.php, B.php and C.php includes (1) & (2) in their own page</DIV>
<DIV>login1.php includes (3)</DIV>
<DIV>login2.php AGAIN includes (1) - (for its local database service)</DIV>
<DIV> </DIV>
<DIV>Basically, in a nutshell, what I'm trying to achieve here is for a user to be able to login from any main page; i.e. A,B or C; and login1.php has the form that gets included in these pages, apart from these pages already including dbconnect.php. </DIV>
<DIV>login1.php then includes login2.php which also includes dbconnect.php for its own use.</DIV>
<DIV> </DIV>
<DIV>So the problem I'm having here is I get the following error when I try to login from any of the 3 main pages:</DIV>
<DIV> </DIV>
<DIV>[Mon Feb 22 12:06:40 2010] [error] [client 127.0.0.1] PHP Fatal error: Cannot redeclare dbconnect() (previously declared in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\xxxxxxx\\includes\\dbconnect.php:2) in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\xxxxxxx\\includes\\dbconnect.php on line 22, referer: <A href="http://localhost/xxxxxxx/A.php" target=_blank rel=nofollow>http://localhost/xxxxxxx/A.php</A> </DIV>
<DIV> </DIV>
<DIV>I get the same error when clicking from AB or C. Only the referer page in the trace changes and the rest are all the same each time.</DIV>
<DIV> </DIV>
<DIV>Then, I tried include_once for all .php's but then I run into empty for-each'es as one below:</DIV>
<DIV> </DIV>
<DIV>[Mon Feb 22 12:26:49 2010] [error] [client 127.0.0.1] PHP Warning: Invalid argument supplied for foreach() in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\kookaburraartgallery\\journal_pdo.php on line 31, referer: <A href="http://localhost/xxxxxxxx/B.php" target=_blank rel=nofollow>http://localhost/xxxxxxxx/B.php</A></DIV>
<DIV> </DIV>
<DIV>Can someone help me with this maze, plz.</DIV>
<DIV> </DIV>
<DIV>thanks</DIV>
<DIV>greymatter</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></TD></TR></TBODY></TABLE><BR><BR>_______________________________________________<BR>PHPwestoz mailing list<BR><A href="http://uk.mc246.mail.yahoo.com/mc/compose?to=PHPwestoz@lists.linux.org.au" target=_blank rel=nofollow>PHPwestoz@lists.linux.org.au</A><BR><A href="http://lists.linux.org.au/listinfo/phpwestoz" target=_blank rel=nofollow>http://lists.linux.org.au/listinfo/phpwestoz</A><BR><BR></BLOCKQUOTE></DIV><BR><BR clear=all><BR>-- <BR>Cheers,<BR>Keith<BR>Australia is merely an island of Antarctica, and of no further significance.<BR></DIV></DIV><BR>-----Inline Attachment Follows-----<BR><BR>
<DIV class=plainMail>_______________________________________________<BR>PHPwestoz mailing list<BR><A href="http://uk.mc246.mail.yahoo.com/mc/compose?to=PHPwestoz@lists.linux.org.au" target=_blank rel=nofollow>PHPwestoz@lists.linux.org.au</A><BR><A href="http://lists.linux.org.au/listinfo/phpwestoz" target=_blank rel=nofollow>http://lists.linux.org.au/listinfo/phpwestoz</A><BR></DIV></BLOCKQUOTE></TD></TR></TBODY></TABLE><BR><PRE><FIELDSET class=mimeAttachmentHeader></FIELDSET>
_______________________________________________
PHPwestoz mailing list
<A class=moz-txt-link-abbreviated href="http://uk.mc246.mail.yahoo.com/mc/compose?to=PHPwestoz@lists.linux.org.au" target=_blank rel=nofollow ymailto="mailto:PHPwestoz@lists.linux.org.au">PHPwestoz@lists.linux.org.au</A>
<A class=moz-txt-link-freetext href="http://lists.linux.org.au/listinfo/phpwestoz" target=_blank rel=nofollow>http://lists.linux.org.au/listinfo/phpwestoz</A>
</PRE></BLOCKQUOTE><BR><PRE class=moz-signature>--
---------------
Kim Richardson
Web Applications Developer
Viewdale IT
Tel: 1300 799 516 - Fax: (07) 3319 8932
<A class=moz-txt-link-freetext href="http://www.ausnix.com.au/" target=_blank rel=nofollow>http://www.ausnix.com.au</A></PRE></DIV><BR>-----Inline Attachment Follows-----<BR><BR>
<DIV class=plainMail>_______________________________________________<BR>PHPwestoz mailing list<BR><A href="http://uk.mc246.mail.yahoo.com/mc/compose?to=PHPwestoz@lists.linux.org.au" ymailto="mailto:PHPwestoz@lists.linux.org.au">PHPwestoz@lists.linux.org.au</A><BR><A href="http://lists.linux.org.au/listinfo/phpwestoz" target=_blank>http://lists.linux.org.au/listinfo/phpwestoz</A><BR></DIV></BLOCKQUOTE></td></tr></table><br>