You are here: Re: Objects and Arrays « PHP Programming Language « IT news, forums, messages
Re: Objects and Arrays

Posted by Jerry Stuckle on 04/03/07 02:52

Simon Stienen wrote:
> On 2007-04-02 16-29-44, Jerry Stuckle wrote:
>> Your problem is you're reusing $db in your class. When you issue:
>>
>> $result = $db->query( $select );
>>
>> You have wiped out the recordset you're using in:
>>
>> while( $db->next_record() )
>>
>> If you're going to make another request, you need to use another object.
>>
>> A real good reason why you shouldn't use globals.
>
> Actually, it's not the global variable that causes the problem, but the bad
> design of the DB class. The problem would be the same if he passed the DB
> object as a parameter to the ctor - however, if the DB class would be
> capable of handling concurrent queries (most likely by letting ::query()
> return a result object), the problem wouldn't occur even with a global
> variable.
>

Not at all a bad design. Any class will do the same thing. It handles
a single query. If you make another query, that will overwrite the
original query. If you want two concurrent queries, you use two db objects.

A variable will do the same thing.


The reason for not using globals is mainly for clarity. It's much more
obvious what's happening when you pass a variable to a function.


> So - yes, the global variable is a desease... but not the one the symptom
> is pointing to. :)
>
>

No, it's not this symptom. But he would have been more likely to see
his problem if he would have passed it as a parameter and not used a global.

> HTH



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация