|
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
==================
[Back to original message]
|