Forums / General Questions / $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

$aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

Views: 2,412

Results 1 to 6 of 6
5 May 2013, 7:36 PM
#1
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

$aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

here are two methods i've tested successfully
i wanna know if i use METHOD B, will i get any insecurity ?

$aaa_query = ""select ...";

METHOD A (zen cart default method)

$aaa = $db->Execute($aaa_query);
while (!$aaa->EOF) {
  echo $aaa->fields['bbb'];
}

METHOD B

$aaa = mysql_query($aaa_query);
while($row = mysql_fetch_array($aaa)){
  echo $row['bbb'];
}
5 May 2013, 7:56 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,118
Plugin Contributions:
56

Re: $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

If you go with option A (i.e. using the integrated Zen Cart database calls), you'll be future-proofed when the mysql* function calls are removed from a future PHP version (they're deprecated in PHP 5.5).

5 May 2013, 8:24 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

Method A is the best one to use within Zen Cart.

But you've got an error in it. You're missing an important line, else you'll end up in an endless loop:

$aaa = $db->Execute($aaa_query);
while (!$aaa->EOF) {
  echo $aaa->fields['bbb'];
[B]  $aaa->MoveNext();[/B]
} 

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

5 May 2013, 9:16 PM
#4
tips007 avatar

tips007

New Zenner

Join Date:
Oct 2012
Posts:
52
Plugin Contributions:
0

Re: $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

sorry i forgot writing $aaa->MoveNext(); just now

yes, Method A is good for zen cart and i use this method for many files for my zen cart,
but for one of my files, i get an issue by this method, then i have to try Method B, it works.
i'm not sure Method B is safe enough, or will it bring any problem? in the future?

DrByte:

Method A is the best one to use within Zen Cart.

But you've got an error in it. You're missing an important line, else you'll end up in an endless loop:

$aaa = $db->Execute($aaa_query);
while (!$aaa->EOF) {
echo $aaa->fields['bbb'];
[B] $aaa->MoveNext();[/B]
}

5 May 2013, 11:13 PM
#5
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

If Method A gives you an issue, then perhaps the file is not truly integrated into Zen Cart. For example, have you included application_top.php?

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

6 May 2013, 4:45 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: $aaa = mysql_query($aaa_query) instead of while (!$aaa->EOF)

Or you're using it from within a function or class, but haven't made the $db global, and thus it's unreachable due to the scope of your code.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.