From gnitnop at ymail.com Mon Mar 1 20:06:32 2010 From: gnitnop at ymail.com (Gnitnop G) Date: Mon, 1 Mar 2010 09:06:32 +0000 (GMT) Subject: [PHPwestoz] problem with includes In-Reply-To: <780fd6311002260537t6bb5bc5ey25bc6ef21167ae0@mail.gmail.com> Message-ID: <901643.26576.qm@web24610.mail.ird.yahoo.com> I'll do that, but in the mean time, as a temporary measure I have gone back to the old fasion way of not using ssi, and it works just fine - not sure whats going wrong. Anyways thanks Keith and Tim and the rest for the help thanks ?greymatter --- On Fri, 26/2/10, Keith Moss wrote: From: Keith Moss Subject: Re: [PHPwestoz] problem with includes To: "PHP users in Western Australia (or nearby)" Date: Friday, 26 February, 2010, 13:37 I think you may need to change foreach($conn->query($sql) as $row) { to $result = $conn->query($sql)->fetchAll(); foreach($result as $row) { On 23 February 2010 16:05, Gnitnop G wrote: Oops! I should have said I'm using mysql PDOs. anyways after a read thru the manual heres what I found. ? "$conn" returns a PDO object "$conn->query($sql)" returns a PDOStatement Object "$query($sql)" returns an array ? since the last line returns an array the $conn object should be iterable. ? 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. ? So I can say after testing that the code is fine when the includes are switched off. ? I also tried persistent connections by?adding another argument in the new PDO constructor 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. ? have anyone struck gold yet? ? thanks greymatter --- On Mon, 22/2/10, Kim Richardson wrote: From: Kim Richardson Subject: Re: [PHPwestoz] problem with includes To: phpwestoz at lists.linux.org.au Date: Monday, 22 February, 2010, 15:27 The output of $conn->query($sql) would be a result set pointer, not an actual array. Try $result=$conn->query($sql); if($result->num_rows>0) { ?? while($row=$result->fetch_assoc()) ?? { ??? ?????? ... do your magic here ?? } } On 22/02/2010 9:58 PM, Gnitnop G wrote: 30 ???
?query($sql) as $row) { ??> ???????

?????????

More'; ????????????? } ?>

????? 41???
? ? ps: according to my sketched-out example, that last error should look like this: ? [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: http://localhost/xxxxxxxx/B.php ? ? ? --- On Mon, 22/2/10, Keith Moss wrote: From: Keith Moss Subject: Re: [PHPwestoz] problem with includes To: "PHP users in Western Australia (or nearby)" Date: Monday, 22 February, 2010, 11:32 Ah I see it's time once again for the annual post to the mailing list :) include_once should indeed work the situation you describe. What was the code around line 31 of journal_pdo.php that was throwing the foreach error? On 22 February 2010 13:30, Gnitnop G wrote: ? Hi All! ? I seem to be having a problem with?php includes. sketching out my problem with an example will look something like this: ? I have 3 main php pages A.php, B.php and C.php. I have 3 include files; (1) dbconnect.php, (2) login1.php (3) login2.php ? All main pages; A.php, B.php and C.php includes (1) & (2) in their own page login1.php includes (3) login2.php AGAIN includes (1) - (for its local database service) ? 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. login1.php then includes login2.php which also includes dbconnect.php for its own use. ? 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: ? [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: http://localhost/xxxxxxx/A.php ? 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. ? Then, I tried include_once for all .php's but then I run into empty for-each'es as one below: ? [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: http://localhost/xxxxxxxx/B.php ? Can someone help me with this maze, plz. ? thanks greymatter ? ? ? ? _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz -- Cheers, Keith Australia is merely an island of Antarctica, and of no further significance. -----Inline Attachment Follows----- _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz -- --------------- Kim Richardson Web Applications Developer Viewdale IT Tel: 1300 799 516 - Fax: (07) 3319 8932 http://www.ausnix.com.au -----Inline Attachment Follows----- _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz -- Cheers, Keith Australia is merely an island of Antarctica, and of no further significance. -----Inline Attachment Follows----- _______________________________________________ PHPwestoz mailing list PHPwestoz at lists.linux.org.au http://lists.linux.org.au/listinfo/phpwestoz -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.linux.org.au/pipermail/phpwestoz/attachments/20100301/284bfa5e/attachment.htm