makenoiz Posted November 10, 2012 Share Posted November 10, 2012 I am having a hard time undestanding this code snippit. Can someone help translate it for me. I guess I dont understand how -> works. and how executing a mysql statement can be a variable Thank you $stats = $db->Execute('select stats_key as stsKey, stats_value as stsValue from myCurrentStats'); while (!$stats->EOF) { if (!defined($stats->fields['stsKey'])) { define($stats->fields['stsKey'], $stats->fields['stsValue']); } $stats->MoveNext(); } Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/ Share on other sites More sharing options...
trq Posted November 10, 2012 Share Posted November 10, 2012 The -> is used to access the properties and methods of an object. In this case, the objects are $db and $stats. $db->Execute() appears to return an object which has been saved into the variable $stats. Where is this code from? This isn't your typical database access code used in PHP. This looks like COM stuff (Windows) and more specifically the JET database engine. Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391446 Share on other sites More sharing options...
makenoiz Posted November 10, 2012 Author Share Posted November 10, 2012 This code is from a program that autopopulates a zencart store. This part reads one of the config tables. When I run this query directly against my database I get about 50 pairs of data (there are 50 records). Im confused why there is no array defined to hold these results. It just does not make sense to me. How can all those 50 pairs of data be held in $stats when $stats is not defined as an array? Thank you.... Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391447 Share on other sites More sharing options...
trq Posted November 10, 2012 Share Posted November 10, 2012 $stats in an object. Objects hold data. I'm really not sure it can be explained any simpler. Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391450 Share on other sites More sharing options...
makenoiz Posted November 10, 2012 Author Share Posted November 10, 2012 Thanks... greatly appreciate your responses. Really any help is great Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391451 Share on other sites More sharing options...
PFMaBiSmAd Posted November 10, 2012 Share Posted November 10, 2012 (edited) $stats holds an instance of the result object that the $db->execute() method creates internally (i.e. $result = new some_result_class();) and returns (i.e return $result;). Methods are like functions, they (optionally) accept input parameters (the query statement in this case), perform some processing (execute the query and hold the result resource from that query internally), and (optionally) returns a result (a custom result object in this case.) The result object (in $stats) has properties (values) and methods that you can access/call. $stats->EOF (End Of File) is a property that is set to TRUE when the ->MoveNext() property method has moved past the last row in the result set from the query. $stats->fields is a property that is an array with at least two indexes/keys - stsKey and stsValue. The properties $stats->fields['stsKey'] and $stats->fields['stsValue'] are set to each successive key and value that the query returned. The $stats->MoveNext() method fetches the next key/value pair from the result set that the query returned and sets the $stats->fields['stsKey'] and $stats->fields['stsValue'] properties with those values. Edited November 10, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391452 Share on other sites More sharing options...
makenoiz Posted November 10, 2012 Author Share Posted November 10, 2012 Perfect... thank you! Quote Link to comment https://forums.phpfreaks.com/topic/270528-too-many-please-translate/#findComment-1391457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.