Zen Cart Logo
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,410

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,080
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:
177

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]
} 
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,690
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?

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

drbyte

Sensei

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

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.