<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>&nbsp;</DIV>
<DIV>"$conn" returns a PDO object<BR>"$conn-&gt;query($sql)" returns a PDOStatement Object<BR>"$query($sql)" returns an array</DIV>
<DIV>&nbsp;</DIV>
<DIV>since the last line returns an array the $conn object should be iterable.</DIV>
<DIV>&nbsp;</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 &nbsp; $conn = dbConnect('query'); new PDO blah blah..) and then the local script A.php has its own include to dbconnect.php.</DIV>
<DIV>&nbsp;</DIV>
<DIV>So I can say after testing that the code is fine when the includes are switched off.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I also tried persistent connections by&nbsp;adding another argument in the new PDO constructor</DIV>
<DIV>array(PDO::ATTR_PERSISTENT =&gt; true); and then making all $conn=null on completion of each&nbsp;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>&nbsp;</DIV>
<DIV>have anyone struck gold yet?</DIV>
<DIV>&nbsp;</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>&lt;krichardson@viewdale.com.au&gt;</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 &lt;krichardson@viewdale.com.au&gt;<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-&gt;query($sql) would be a result set pointer, not an actual array. <BR><BR>Try <BR><BR>$result=$conn-&gt;query($sql);<BR>if($result-&gt;num_rows&gt;0)<BR>{<BR>&nbsp;&nbsp; while($row=$result-&gt;fetch_assoc())<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... do your magic here<BR>&nbsp;&nbsp; }<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 &nbsp;&nbsp;&nbsp; &lt;div id="artdescription"&gt;<BR>&nbsp;&lt;?php<BR>&nbsp;foreach ($conn-&gt;query($sql) as $row) {<BR>&nbsp;?&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;h2&gt;&lt;?php echo $row['title']; ?&gt;&lt;/h2&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;&lt;?php $extract = getFirst($row['article']);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $extract[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($extract[1]) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo '&lt;a href="abstractexplanation.php?article_id='.$row['article_id'].'"&gt; More&lt;/a&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
 ?&gt;&lt;/p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php } ?&gt;<BR>41&nbsp;&nbsp;&nbsp; &lt;/div&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>ps: according to my sketched-out example, that last error should look like this:</DIV>
<DIV>&nbsp;</DIV>
<DIV>[Mon Feb 22 12:26:49 2010] [error] [client 127.0.0.1] PHP Warning:&nbsp; 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>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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">&lt;khan@swcombine.com&gt;</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">&lt;khan@swcombine.com&gt;</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">&lt;phpwestoz@lists.linux.org.au&gt;</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>&lt;<A href="http://uk.mc246.mail.yahoo.com/mc/compose?to=gnitnop@ymail.com" target=_blank rel=nofollow>gnitnop@ymail.com</A>&gt;</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>&nbsp;</DIV>
<DIV>Hi All!</DIV>
<DIV>&nbsp;</DIV>
<DIV>I seem to be having a problem with&nbsp;php includes. sketching out my problem with an example will look something like this:</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>All main pages; A.php, B.php and C.php includes (1) &amp; (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>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>[Mon Feb 22 12:06:40 2010] [error] [client 127.0.0.1] PHP Fatal error:&nbsp; 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>&nbsp;</DIV>
<DIV>I get the same error when clicking from AB or C. Only the referer page in the trace changes and&nbsp;the rest are all the same each time.</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>[Mon Feb 22 12:26:49 2010] [error] [client 127.0.0.1] PHP Warning:&nbsp; 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>&nbsp;</DIV>
<DIV>Can someone help me with this maze, plz.</DIV>
<DIV>&nbsp;</DIV>
<DIV>thanks</DIV>
<DIV>greymatter</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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>