Jump to content

Recommended Posts

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();
}

Link to comment
https://forums.phpfreaks.com/topic/270528-too-many-please-translate/
Share on other sites

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.

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....

$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 by PFMaBiSmAd
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.